【思路】:把吃糖的行为看成是两两消除的行为,所以如果想全部消除,取决于数量最多的那种。所以得出公式:max - (sum-max)<= 1.另外:要采用longlong型。
【AC代码】:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> #include <iomanip> using namespace std; #define MAX 1000000+10 int num[MAX]; int main() { //freopen("in.txt", "r", stdin); int T = 0; cin >> T; while (T--) { int i = 0; long long int N = 0, sum = 0, mmax = 0; cin >> N; for(i = 0; i < N; i++) { scanf("%d", &num[i]); sum += num[i]; if (num[i] > mmax) mmax = num[i]; } if (mmax-1 <= sum-mmax) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
原文地址:http://blog.csdn.net/weijj6608/article/details/43925461