zoukankan      html  css  js  c++  java
  • Codeforces Round #341 (Div. 2) A

    Description

    Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.

    Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

    Input

    The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.

    Output

    Print the maximum possible even sum that can be obtained if we use some of the given integers.

    Sample test(s)
    input
    3
    1 2 3
    output
    6
    input
    5
    999999999 999999999 999999999 999999999 999999999
    output
    3999999996
    Note

    In the first sample, we can simply take all three integers for a total sum of 6.

    In the second sample Wet Shark should take any four out of five integers 999 999 999.

    偶数+偶数=偶数 万一是奇数就奇数-奇数=偶数 要得到最大偶数,那么减去一个最小奇数就好

    #include<stdio.h>
    //#include<bits/stdc++.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<queue>
    #include<map>
    #include<vector>
    #include<algorithm>
    #include<limits.h>
    #define inf 0x3fffffff
    #define INF 0x3f3f3f3f
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define ULL unsigned long long
    using namespace std;
    struct P
    {
        int a;
        LL num;
    }L[1000000];
    bool cmd(P x,P y)
    {
        return x.num<y.num;
    }
    int main()
    {
        int n;
        LL sum=0;
        int j;
        int i;
        int ans1=0,ans2=0;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>L[i].num;
            if(L[i].num%2==0)
            {
                L[i].a=0;
            }
            else
            {
                L[i].a=1;
            }
            sum+=L[i].num;
        }
        if(sum%2==0)
        {
            cout<<sum<<endl;
            return 0;
        }
        else
        {
          //  cout<<sum-999999999<<endl;
            sort(L,L+n,cmd);
            for(j=0;j<n;j++)
            {
                if(L[j].num%2==1)
                {
                    sum=sum-L[j].num;
                    break;
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    HDU3336 Count the string(kmp
    HDU2087 剪花布条(字符串...半暴力写的?
    HDU4763 Theme Section(kmp
    HDU1251 统计难题(字典树|map
    HDU1305 Immediate Decodability (字典树
    priority_queue member function
    HDU
    洛谷 P3370 【模板】字符串哈希 (set||map||哈希||字典树(mle)
    mysql (master/slave)复制原理及配置
    mysql备份小记
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5176572.html
Copyright © 2011-2022 走看看