日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

14行代码AC_Zero Array(思维)

發布時間:2024/2/28 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 14行代码AC_Zero Array(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

立志用更少的代碼做更高效的表達


You are given an array a1,a2,…,an.In one operation you can choose two elements ai and aj (i≠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 n (2≤n≤105) — the size of the array.The second line contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.

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

Input
4
1 1 2 2

Output
YES

Input
6
1 2 3 4 5 6

Output
NO


思路: 考查思維,判斷和是否是偶數或最大值大于和的一半。


代碼展示

#include<bits/stdc++.h> using namespace std; int main() {long long n; while(cin>>n) {long long sum = 0;long long Max = -1;for(int i = 0; i < n; i++) {long long x; cin>>x;sum += x;Max = max(Max, x);}cout << (sum%2==1||Max>sum/2 ? "NO" : "YES") << '\n';} return 0; }

每日一句

先努力讓自己發光,對的人才能迎著光而來。

總結

以上是生活随笔為你收集整理的14行代码AC_Zero Array(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。