Codeforces 892A Greed

来源:互联网 发布:淘宝上卖的冷光美白仪 编辑:程序博客网 时间:2024/06/06 01:16

#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");}elseprintf("YES\n");//system("pause");return 0;}

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

数据范围爆int,改用ll。


原创粉丝点击