• CodeForces


    You are given an array a1,a2,,ana1,a2,…,an.

    In one operation you can choose two elements aiai and ajaj (iji≠j) and decrease each of them by one.

    You need to check whether it is possible to make all the elements equal to zero or not.

    Input

    The first line contains a single integer nn (2n1052≤n≤105) — the size of the array.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) — the elements of the array.

    Output

    Print "YES" if it is possible to make all elements zero, otherwise print "NO".

    Examples

    Input
    4
    1 1 2 2
    
    Output
    YES
    Input
    6
    1 2 3 4 5 6
    
    Output
    NO


    题意:

    给你n个数,你可以每次找到两个数并且让它们都减去1.问你可不可以到最后这n个数都变成0

    题解:

    首先我们可以确定,如果这些数的和是一个奇数的话,那么肯定输出NO。这n个数里面,如果每一次都对这n个数里面的最大值和第二大值进行减1操作。那么减到最后肯定可以全部减为0(前提就是:这n个数里面的最大值肯定要小于其他数之和)

    代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 int main()
     7 {
     8     long long n,sum=0,a,maxx=0;
     9     scanf("%I64d",&n);
    10     for(long long i=0;i<n;++i)
    11     {
    12         scanf("%I64d",&a);
    13         sum+=a;
    14         maxx=max(maxx,a);
    15     }
    16     if(sum-maxx>=maxx)
    17     {
    18         if(sum%2)
    19             printf("NO
    ");
    20         else printf("YES
    ");
    21     }
    22     else printf("NO
    ");
    23 }
    View Code
  • 相关阅读:
    软工1816 · 第四次作业
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    软工 第七次作业
    软工实践第八次作业
    软工实践第六次作业——团队选题报告
    软工实践第二次结对作业(作业五)
    软工第四次作业
    软工实践第三次作业
  • 原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/11835839.html
Copyright © 2020-2023  润新知