Codeforces Round #446 (Div. 2) A. Greed【模拟】
2 seconds
256 megabytes
standard input
standard output
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans.
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
2
3 5
3 6
YES
3
6 8 9
6 10 12
NO
5
0 0 5 0 0
1 1 8 10 5
YES
4
4 1 0 3
5 2 2 3
YES
In the first sample, there are already 2 cans, so the answer is "YES".
【分析】:
we sort the capacities in nonincreasing order and let s = capacity1 + capacity2 if
the answer is no and otherwise the answer is yes。
注意爆int,用LL
【代码】:
#include <bits/stdc++.h> using namespace std;
typedef long long ll;
const int N = ;
ll a[N],b[N];
int main()
{
int n;
ll sum=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
sum+=a[i];
}
for(int i=;i<n;i++)
{
scanf("%lld",&b[i]);
}
sort(b,b+n);
if(sum<=b[n-]+b[n-])
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return ;
}
最新文章
- python Django 进阶篇
- 25佳漂亮的结婚邀请 &; 婚礼请柬网站设计
- (转)ElasticSearch学习
- 让finder显示路径
- set_exception_handler 和 set_error_handler 函数
- HDU 2836 Traversal 简单DP + 树状数组
- vs2010旗舰版产品密钥
- CentOS中使用shell的命令补全
- vue+express之前后台分离博客
- Swoole笔记(五)
- nyoj888 取石子(九) 反Nimm博弈
- SQL语句异常导致项目报错
- ADC0832的应用
- 【AGC 002F】Leftmost Ball
- gevent模块学习(三)
- python基础-动态加载lazy_import(利用__import__)
- Ubuntu下配置eclipse
- js中对象转化成字符串、数字或布尔值的转化规则
- phpsso 与 Discuz!
- iOS开发ReactiveCocoa学习笔记(一)