Codeforces 892A. 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<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll num[100010];
bool cmp(int a,int b){return a>b;
}
int main(){ll sum=0;int n;cin>>n;for(int i=0;i<n;i++){int a;cin>>a;sum+=a;}for(int i=0;i<n;i++){cin>>num[i];}sort(num,num+n,cmp);if(num[0]+num[1]>=sum) cout<<"YES"<<endl;else cout<<"NO"<<endl;
}
Codeforces 892A. Greed相关推荐
- [CodeForces 892A] Greed (Java中sort实现从大到小排序)
题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...
- codeforces 892A. Greed(水)
题意:现在有N瓶可乐,问有没有可能合到两个瓶子里面?第二行表示剩余可乐体积,第三行表示容量. 思路:维护一个最大值和一个次大值,判断总剩余可乐的体积跟这两个值之和的大小就OK. 我还智障的WA了一发, ...
- A - Greed CodeForces - 892A(水题)
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can ...
- 892A Greed
很简单,但是注意会超int 范围~ A. Greedtime limit per test2 secondsmemory limit per test256 megabytesinputstandar ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- Codeforces 892 A.Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- codeforces 博弈 Arena of Greed
题目描述: 思想: 首先,我们应该明确,如果一开始石子的数量为偶数,那么先手可以控制后手的选择,因为先手可以拿一个,那么后手也只能拿一个,先手的局面又变为偶数了.如果先手拿走一半后,石子的数量只剩下奇 ...
- Codeforces 892 A Greed(水题)
题目链接:点击打开链接 题目大意:现在要把所有剩余的可乐倒进2个罐子里,问能不能实现? 代码如下: #include<iostream> #include<algorithm> ...
- A. Arena of Greed
链接:https://codeforces.com/problemset/problem/1425/A Lately, Mr. Chanek frequently plays the game Are ...
最新文章
- 自定义标签报 无法为TAG [my2:hello]加载标记处理程序类[null]
- Back 键与Home键
- JavaScript DOM 编程艺术 --- JavaScript语法
- 监控主机安装需要材料
- 走进PV,UV,IP,session
- python在哪里画柱形图_Python笔记:用pyecharts绘制柱形图
- Three.js视频教程
- 关于PHP 源码 加密的 一些 学习(黑刀)
- Myeclipse 10破解run.bat和cracker.jar打不开的问题
- 给出直角三角形斜边,求有多少三角形符合要求
- WTS 2.1.18124.1 彻底抛弃了 15063(Win 10 创意者更新)
- 微软bi报表服务器,为 Power BI 报表服务器创建 Power BI 报表
- 最近超火的100句土味情话合集,拿去撩妹撩汉吧!
- 00007__文本编辑器__UltraEdit
- [陕师大校赛] A 正正的毒奶粉
- 私有云与公有云区别,公有云不可能统一天下
- 牛客网 KY11 二叉树遍历
- 【MySQL】幻读是什么?如何避免幻读?
- 【c++复健】双指针(第二弹)
- 关于嵌套结构体大小的计算
热门文章
- python 隐函数绘制_Python隐函数作图
- R语言逻辑操作符:、|、!、||
- CSS实现背景网格线(background-image)
- rc52实现的部分代码
- oracle 手工创建数据库
- linux内核led驱动开发,从Linux内核LED驱动来理解字符设备驱动开发流程
- 手机搜狐 html5,手机搜狐欲改版推全新域名及LOGO 着力Html5技术
- 深入理解Java Stream流水线
- Hello, World! 发明者布莱恩·W.克尼汉的传奇人生
- Swift 中的类与结构体