Codeforces 892A Greed

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/polanwind/article/details/78570846

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	long long tot = 0;
	for (int i = 1;i <= n;++i) {
		int v;
		scanf("%d", &v);
		tot += v;
	}
	int mmax=-1;
	int max=-1;
	for (int i = 1;i <= n;++i) {
		int v;
		scanf("%d", &v);
		if(v>mmax){
			max = mmax;
			mmax = v;
		}
		else if (v >= max) {
			max = v;
		}
	}
	if (tot > (mmax + max)) {
		printf("NO\n");
	}
	else
		printf("YES\n");
//	system("pause");
	return 0;
}

求一个sum并与最大的两个容量之和作比较即可。

数据范围爆int,改用ll。


猜你喜欢

转载自blog.csdn.net/polanwind/article/details/78570846