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;
    }
    

      

  • 相关阅读:
    Swift 编程语言新手教程
    标准差(standard deviation)和标准错误(standard error)你能解释一下?
    shell文字过滤程序(十一):paste命令
    java 获取系统变量(环境变量和环境变量)
    MD5算法原理
    受托停止事件冒泡
    搜索引擎优化要领:8条辅助技巧(三)
    几种更新(Update语句)查询的方法
    学习盲点
    2014年同年CFA考试中哪些CFA资料没有变化?
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5176572.html
Copyright © 2011-2022 走看看