很简单,但是注意会超int 范围~

                        A. Greedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int a[N],b[N];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
long long n,sum;
while(cin>>n)
{sum=0;for(int i=0; i<n; i++){cin>>a[i];sum+=a[i];}for(int i=0; i<n; i++)cin>>b[i];sort(b,b+n,cmp);if(sum<=b[0]+b[1])puts("YES");else puts("NO");}
return 0;

}

892A Greed相关推荐

  1. Codeforces 892A. Greed

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

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

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

  3. codeforces 892A. Greed(水)

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

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

    961A - Tetris                                                模拟                                      ...

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

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

  6. 恐惧贪婪指数(Fear Greed Index)

    一.介绍 恐惧贪婪指数(Fear & Greed Index,也称为恐惧与贪婪指数)是由德国软件供应商Alternative(https://alternative.me/) 提供,其官网地址 ...

  7. A. Arena of Greed

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

  8. Codeforces 892 A.Greed

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

  9. codewars打怪日记 Greed is Good JavaScript中数组用法和 哈希表的使用

    codewars是一个在线编程网站,其奖励机制像打怪升级.你不能查看高于你级别的问题的答案.除非自己通过提交测试.通过提交之后可以看到各种解法排行榜 .通过对比自己解法和排行榜对比,可以找到差距,提高 ...

最新文章

  1. HDU2066(SPFA算法)
  2. findcontours 崩溃
  3. 疑似华为Mate X 5G版入网 将支持两种组网方式
  4. OC算法练习-Hash算法
  5. asp.net创建自定义排序用户界面
  6. 4)Thymeleaf th:each 循环迭代与 th:if、th:switch 条件判断
  7. MAC下 安装sqlmap教程
  8. 数据分析职位需求分析报告-数据来源于Boss直聘网站
  9. 惠普z800工作站bios设置_惠普台式机装win10系统及bios设置(uefi+gpt)
  10. Android——Intent总结
  11. siri中文语音助理_针对“语音助手”类产品,浅谈对话式交互设计
  12. ssm客户关系管理系统
  13. 5.3.1 Unique Binary Sear Trees
  14. 基于jsp+mysql+ssm高校学生成绩管理系统-计算机毕业设计
  15. 40个重要的HTML5面试题及答案
  16. php 处理透明 png 图片黑边问题
  17. pythonweb全栈开发_Python web全栈学习路线
  18. 3.DesignForVias\AlignVia
  19. 用计算机VLOOKUP,vlookup怎么用?
  20. PHP房贷计算器算法

热门文章

  1. 洛谷P2404 自然数的拆分问题
  2. AD导入PCB后模型出现绿色叉叉报错的解决办法
  3. 如何用python计算函数的值域_(完整版)求函数定义域及值域方法及典型题归纳
  4. 模拟丢包、慢网速的测试工具
  5. 划水摸鱼的时候写一篇自己是怎么划水摸鱼的
  6. 【单目摄像头测量距离:相似三角形法】
  7. 方法模板ThinkPHP3.1.2项目技巧三部曲 一
  8. Docker 搭建 Jenkins 流水线项目配置
  9. 贝叶斯决策理论(三):最小最大决策、序贯分类
  10. 文笔很差系列2 - 真实的世界