892A Greed
很简单,但是注意会超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相关推荐
- Codeforces 892A. Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- [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了一发, ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- A - Greed CodeForces - 892A(水题)
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can ...
- 恐惧贪婪指数(Fear Greed Index)
一.介绍 恐惧贪婪指数(Fear & Greed Index,也称为恐惧与贪婪指数)是由德国软件供应商Alternative(https://alternative.me/) 提供,其官网地址 ...
- A. Arena of Greed
链接:https://codeforces.com/problemset/problem/1425/A Lately, Mr. Chanek frequently plays the game Are ...
- Codeforces 892 A.Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- codewars打怪日记 Greed is Good JavaScript中数组用法和 哈希表的使用
codewars是一个在线编程网站,其奖励机制像打怪升级.你不能查看高于你级别的问题的答案.除非自己通过提交测试.通过提交之后可以看到各种解法排行榜 .通过对比自己解法和排行榜对比,可以找到差距,提高 ...
最新文章
- HDU2066(SPFA算法)
- findcontours 崩溃
- 疑似华为Mate X 5G版入网 将支持两种组网方式
- OC算法练习-Hash算法
- asp.net创建自定义排序用户界面
- 4)Thymeleaf th:each 循环迭代与 th:if、th:switch 条件判断
- MAC下 安装sqlmap教程
- 数据分析职位需求分析报告-数据来源于Boss直聘网站
- 惠普z800工作站bios设置_惠普台式机装win10系统及bios设置(uefi+gpt)
- Android——Intent总结
- siri中文语音助理_针对“语音助手”类产品,浅谈对话式交互设计
- ssm客户关系管理系统
- 5.3.1 Unique Binary Sear Trees
- 基于jsp+mysql+ssm高校学生成绩管理系统-计算机毕业设计
- 40个重要的HTML5面试题及答案
- php 处理透明 png 图片黑边问题
- pythonweb全栈开发_Python web全栈学习路线
- 3.DesignForVias\AlignVia
- 用计算机VLOOKUP,vlookup怎么用?
- PHP房贷计算器算法