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

【分析】:

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【模拟】的更多相关文章

  1. Codeforces Round #446 (Div. 2)

    Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...

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

  3. 【Codeforces Round #446 (Div. 2) A】Greed

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心选容量大的瓶子就好 [代码] #include <bits/stdc++.h> #define int long l ...

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

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

  6. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  7. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  8. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  9. Codeforces Round #371 (Div. 2) C 大模拟

    http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一 ...

随机推荐

  1. 获取访问者ip及其所在城市

    原本使用新浪Api,然后发现不行了,以下小编重新查找了几个,个人推荐太平洋的接口 1.首先获取真实ip $ip = $_SERVER['REMOTE_ADDR']; 2.要知道的Api接口 几个接口$ ...

  2. Eclipse 出现“polling news feeds”的解决办法

    小编突然心血来潮,安装了一下Java的环境,eclipse的IDE来写点Java,但是是不是出现以下的弹窗,实在是闹心,后来网上看了前辈们的解决办法,特此记录一下.如有侵权,敬请告知!!! 1. 找到 ...

  3. Singleton patterns 单件(创建型模式)

    1.模式分类 1.1  从目的来看: •      – 创建型(Creational)模式:负责对象创建. •      – 结构型(Structural)模式:处理类与对象间的组合. •      ...

  4. python学习总结----时间模块 and 虚拟环境(了解)

    time - sleep:休眠指定的秒数(可以是小数) - time:获取时间戳 # 获取时间戳(从1970-01-01 00:00:00到此刻的秒数) t = time.time() print(t ...

  5. (原、整)Unreal源码 CoreUbject- Uobject

    (原.整) Unreal源码 CoreUbject- Uobject 类别                    [随笔分类]Unreal源码搬山 @author:白袍小道 随缘那啥 这里还是属于UE ...

  6. 云效(阿里云)流水线 + nginx + uWsgi + flask + python3 基础环境搭建 --备忘

    一.开发环境搭建 1.安装python3 yum -y groupinstall "Development tools" yum -y install zlib-devel bzi ...

  7. ubuntu16.04 搭建nexus+maven 学习

    /opt/nexus-2.10.0-02/bin vim nexus 关键配置: RUN_AS_USER=root JAVA_HOME=/usr/lib/java/jre export NEXUS_H ...

  8. Redis键管理

    Redis键管理 Redis 键命令用于管理 redis 的键. 语法 Redis 键命令的基本语法如下: redis > COMMAND KEY_NAME redis > SET w3c ...

  9. ZooKeeper客户端 zkCli.sh 节点的配额设置

    首先使用 zkCli.sh 连接上ZooKeeper服务器 配额设置命令格式如下: setquota -n|-b val path -n:val设置子节点个数 -b:val设置节点的数据长度 如果我们 ...

  10. 【bzoj2396】神奇的矩阵 随机化

    题目描述 给出三个行数和列数均为N的矩阵A.B.C,判断A*B=C是否成立. 输入 题目可能包含若干组数据.对于每组数据,第一行一个数N,接下来给出三个N*N的矩阵,依次为A.B.C三个矩阵. 输出 ...