A. Greed
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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!

Input

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.

Output

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).

Examples
input
2
3 5
3 6

output
YES

input
3
6 8 9
6 10 12

output
NO

input
5
0 0 5 0 0
1 1 8 10 5

output
YES

input
4
4 1 0 3
5 2 2 3

output
YES

Note

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相关推荐

  1. [CodeForces 892A] Greed (Java中sort实现从大到小排序)

    题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...

  2. codeforces 892A. Greed(水)

    题意:现在有N瓶可乐,问有没有可能合到两个瓶子里面?第二行表示剩余可乐体积,第三行表示容量. 思路:维护一个最大值和一个次大值,判断总剩余可乐的体积跟这两个值之和的大小就OK. 我还智障的WA了一发, ...

  3. A - Greed CodeForces - 892A(水题)

    Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can ...

  4. 892A Greed

    很简单,但是注意会超int 范围~ A. Greedtime limit per test2 secondsmemory limit per test256 megabytesinputstandar ...

  5. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

  6. Codeforces 892 A.Greed

    A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  7. codeforces 博弈 Arena of Greed

    题目描述: 思想: 首先,我们应该明确,如果一开始石子的数量为偶数,那么先手可以控制后手的选择,因为先手可以拿一个,那么后手也只能拿一个,先手的局面又变为偶数了.如果先手拿走一半后,石子的数量只剩下奇 ...

  8. Codeforces 892 A Greed(水题)

    题目链接:点击打开链接 题目大意:现在要把所有剩余的可乐倒进2个罐子里,问能不能实现? 代码如下: #include<iostream> #include<algorithm> ...

  9. A. Arena of Greed

    链接:https://codeforces.com/problemset/problem/1425/A Lately, Mr. Chanek frequently plays the game Are ...

最新文章

  1. 自定义标签报 无法为TAG [my2:hello]加载标记处理程序类[null]
  2. Back 键与Home键
  3. JavaScript DOM 编程艺术 --- JavaScript语法
  4. 监控主机安装需要材料
  5. 走进PV,UV,IP,session
  6. python在哪里画柱形图_Python笔记:用pyecharts绘制柱形图
  7. Three.js视频教程
  8. 关于PHP 源码 加密的 一些 学习(黑刀)
  9. Myeclipse 10破解run.bat和cracker.jar打不开的问题
  10. 给出直角三角形斜边,求有多少三角形符合要求
  11. WTS 2.1.18124.1 彻底抛弃了 15063(Win 10 创意者更新)
  12. 微软bi报表服务器,为 Power BI 报表服务器创建 Power BI 报表
  13. 最近超火的100句土味情话合集,拿去撩妹撩汉吧!
  14. 00007__文本编辑器__UltraEdit
  15. [陕师大校赛] A 正正的毒奶粉
  16. 私有云与公有云区别,公有云不可能统一天下
  17. 牛客网 KY11 二叉树遍历
  18. 【MySQL】幻读是什么?如何避免幻读?
  19. 【c++复健】双指针(第二弹)
  20. 关于嵌套结构体大小的计算

热门文章

  1. python 隐函数绘制_Python隐函数作图
  2. R语言逻辑操作符:、|、!、||
  3. CSS实现背景网格线(background-image)
  4. rc52实现的部分代码
  5. oracle 手工创建数据库
  6. linux内核led驱动开发,从Linux内核LED驱动来理解字符设备驱动开发流程
  7. 手机搜狐 html5,手机搜狐欲改版推全新域名及LOGO 着力Html5技术
  8. 深入理解Java Stream流水线
  9. Hello, World! 发明者布莱恩·W.克尼汉的传奇人生
  10. Swift 中的类与结构体