Codeforces 892 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".
分析:签到题,排个序看容量最大的杯子能否装下.
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; long long n, a[], b[], sum; int main()
{
cin >> n;
for (int i = ; i <= n; i++)
{
long long t;
cin >> t;
sum += t;
}
for (int i = ; i <= n; i++)
cin >> b[i];
sort(b + , b + + n);
if (sum <= b[n] + b[n - ])
puts("YES");
else
puts("NO"); return ;
}
Codeforces 892 A.Greed的更多相关文章
- codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony
A 链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...
- codeforces 892 - A/B/C
题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...
- Codeforces 892 C.Pride
C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces 892 D.Gluttony
D. Gluttony time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces 892 B.Wrath
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- War of the Corporations CodeForces - 625B (greed)
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue the ...
- [CodeForces 892A] Greed (Java中sort实现从大到小排序)
题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...
- Codeforces Round #446 (Div. 2) A. Greed【模拟】
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces 620C EDU C.Pearls in a Row ( set + greed )
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...
随机推荐
- bootstrap div 固定
div固定在顶部样式: .navbar-fixed-top div固定在底部样式 .navbar-fixed-bottom
- MVC:html动态追加行及取值
先一个button id=addRow 点击事件进行添加 $("#addRow").bind("click", function () { var addH ...
- js由浅入深理解
隐式转换 + - num - 0 把num转换成number: num + "" 把num转换成字符串: ------------------------------------- ...
- MongoDB最简单的入门教程之一 环境搭建
MongoDB是近年来非常流行的一个介于关系数据库和非关系数据库之间的解决方案,特别广泛地应用于国内很多互联网公司,是非关系数据库当中功能最丰富,最像关系数据库的. MongoDB支持的数据结构非常松 ...
- 【Android】ListView中EditText焦点问题
一.描述: 近期一个项目中需要开发一种类似表格的界面来显示和配置参数,Android并无直接类似表格的控件支持,我采用了ListView中布局EditText和TextView来实现,其中TextVi ...
- docker 深入理解之cgroups
cgroups 资源限制 cgroups 是什么 cgroups 最初名为process container,有Google工程师Paul Menage和Rohit Seth于 2006 年提出,后由 ...
- 查看python关键字
打开命令窗口 输入python-——help()——keywords
- arx 地址
2014(32位和64位版本) ObjectARX 2014 SDKObjectARX 2014 帮助文档2013(32位和64位版本) ObjectARX 2013 SDKObjectARX 201 ...
- 模板引擎freemarker的使用(二)
freemarker默认配置使用时,如果传到前端的值为null或者不存在,后台会报错. 处理方法: <bean id="freemarkerConfig" class=&qu ...
- xlsx 读取文件日期问题
xlsx 的版本:0.13.5,可以取到日期 xlsx 的版本:0.14.3,取到的日期转为数字了,没有找到方法转为日期, 可以开启 cellDates: true,但是这个时区不对, dateN ...