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 ...
随机推荐
- Spring------自动化装配Bean(三)
上一篇是基于java手动装配bean的实现,这一篇将通过xml手动装配bean来实现. xml配置相对于java配置有点: xml配置更加快捷 但不宜扩展 一.打开application.xml 1. ...
- php url地址栏传中文乱码解决方法集合
php地址栏传中文$_GET下来后乱码,urlencode和urldecode,iconv,base64_encode等方法,整理基本是常用的了. php地址栏传中文$_GET下来后乱码,urlen ...
- c#自定义鼠标形状
更改鼠标指针,需要使用到 Windows API: 1. 添加命名空间的引用: using System.Runtime.InteropServices; using System.Reflectio ...
- poj2139 Six Degrees of Cowvin Bacon
思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- c# sqlserver连接字符串
odbc: string cnnstring = @"Driver={SQL Server Native Client 11.0};Initial Catalog = sxquadb;ser ...
- Javascript中setTimeout()以及clearTimeout( )的使用
setTimeout setTimeout( ) 是属于 window 的 method, 这是用来设定一个时间,时间到了, 就会执行一个指定的 方法.练习一:等候三秒才执行的 alert( )set ...
- socket是什么?协议栈操作的抽象
http://www.cnblogs.com/airtcp/p/5230161.html TCP/IP只是一个协议栈,就像操作系统的运行机制一样,必须要具体实现,同时还要提供对外的操作接口.就像操作系 ...
- 浅析HashSet add() 方法存储自定义类型对象的过程
一.自定义一个Student类 package date0504; public class Student { private String id; Student(String id){ this ...
- Apache安装和文件配置
Apache和Tomcat的区别是:静态文件和动态页面,C++和Java的区别. 对比.
- vscode vue template 下 style 的样式自动提示 #bug 这个搞完vue语法esLint就又不好使了,ERR
网上都是 "*.vue": "vue",改成"*.vue": "html" 就ok了 "files.ass ...