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

分析:签到题,排个序看容量最大的杯子能否装下.

#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的更多相关文章

  1. codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony

    A  链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...

  2. codeforces 892 - A/B/C

    题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...

  3. Codeforces 892 C.Pride

    C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  4. Codeforces 892 D.Gluttony

    D. Gluttony time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  5. Codeforces 892 B.Wrath

    B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

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

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

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

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

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

随机推荐

  1. CSS实现文字旋转/实现角标

    主要用到属性transform:rotate(-30deg) example: .divedittable .project-tag div { width: 43px; line-height: 4 ...

  2. 什么是极坐标? —— 一点微小的想法 What is Polar Coordinate ? - Some Naive Thoughts about It

    Can you answer these three questions? The answer seems to be trivial, since we can use our eyes to o ...

  3. CF749C Voting

    题目链接: http://codeforces.com/problemset/problem/749/C 题目大意: 共有n个人,编号为1~n.他们每个人属于且仅属于R阵营或N阵营中的一个.现在他们要 ...

  4. java实现课堂随机点名小程序

    通过jdbc连接数据库实现读取学生花名册进行随机点名! ~jdbc连接mysql数据库  ||  注释部分代码可通过读取.txt文档实现显示学生信息 ~通过点击开始按钮实现界面中间标签不断更新学生信息 ...

  5. Android如何用阿里云的API进行身份证识别

    准备工作:在libs下添加 alicloud-Android-apigateway-sdk-1.0.1.jar,commons-codec-1.10-1.jar 在build.gradle添加  co ...

  6. dns2tcp使用教程

    在2010年6月的更新(也是迄今为止最新的更新)后,其源代码支持编译为Windows平台的可执行程序.而且此工具使用C语言开发编写,不需要TUN/TAP,所以大大加强了它的可用性. 下载 当前最新的0 ...

  7. js 数组过滤 filter

    let res = this.list.filter(item => routeEqual(this.currentRouteObj, item) || item.name === this.$ ...

  8. C-基础:冒泡排序

    #include <fstream> #include <iostream.h> //--------------------------------------------- ...

  9. 并发3-Volatile

    Volatile关键字实现原理 1.认识volatile关键字 程序举例 用一个线程读数据,一个线程改数据 存在数据的不一致性 2.机器硬件CPU与JMM (1)CPU Cache模 (2)CPU缓存 ...

  10. java list去重操作实现方式

    Java中的List是可以包含重复元素的(hash code 和equals),接下来将介绍两种方式实现java list去重操作,感兴趣的朋友可以参考下   Java中的List是可以包含重复元素的 ...