Codeforces Round #446 (Div. 2) 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".
【分析】:
we sort the capacities in nonincreasing order and let s = capacity1 + capacity2 if
the answer is no and otherwise the answer is yes。
注意爆int,用LL
【代码】:
#include <bits/stdc++.h> using namespace std;
typedef long long ll;
const int N = ;
ll a[N],b[N];
int main()
{
int n;
ll sum=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
sum+=a[i];
}
for(int i=;i<n;i++)
{
scanf("%lld",&b[i]);
}
sort(b,b+n);
if(sum<=b[n-]+b[n-])
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return ;
}
Codeforces Round #446 (Div. 2) A. Greed【模拟】的更多相关文章
- Codeforces Round #446 (Div. 2)
Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...
- Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 【Codeforces Round #446 (Div. 2) A】Greed
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心选容量大的瓶子就好 [代码] #include <bits/stdc++.h> #define int long l ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...
- Codeforces Round #398 (Div. 2) A. Snacktower 模拟
A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...
- Codeforces Round #237 (Div. 2) B题模拟题
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...
- Codeforces Round #371 (Div. 2) C 大模拟
http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一 ...
随机推荐
- Unicode字符图标
http://unicode-table.com/cn/#control-character
- sweetalert : 一个比较好看的弹出框
1.引入 <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"> </script& ...
- git bash中文显示为数字
转自:http://blog.csdn.net/zhujiangtaotaise/article/details/74424157 今天让去做一个另外一个项目,导入项目后,git status 发现原 ...
- Singleton patterns 单件(创建型模式)
1.模式分类 1.1 从目的来看: • – 创建型(Creational)模式:负责对象创建. • – 结构型(Structural)模式:处理类与对象间的组合. • ...
- VS配置使用第三方库
VS使用第三方库 项目设置 调整头文件引用目录 C/C++ -> General -> Additional Include Directories 添加库文件目录 Linker -> ...
- java与C#对比文章阅读
文章:JAVA与C#的区别 讲了C#与java一些基本异同. 易语言官网有个表,比较了易语言.Java.C#的区别,比较全面可以借鉴.
- nyoj 题目44 子串和
子串和 时间限制:5000 ms | 内存限制:65535 KB 难度:3 描述 给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最 ...
- 201621123033 《Java程序设计》第2周学习总结
1. 本周学习总结 ·学习了String类的特点,以及其与字符数组的关系等等. ·常量池的相关概念. ·包装类的特点. 2. 书面作业 1. String-使用Eclipse关联jdk源代码 1.1 ...
- MySQL之优化总结
http://www.cnblogs.com/benshan/archive/2012/07/27/2612212.html MySQL之优化总结 今天,数据库的操作越来越成为整个应用的性能瓶颈 ...
- 多线程 线程池 ExecutorService
package org.zln.thread; import java.util.Date; import java.util.concurrent.ExecutorService; import j ...