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. Spring------自动化装配Bean(三)

    上一篇是基于java手动装配bean的实现,这一篇将通过xml手动装配bean来实现. xml配置相对于java配置有点: xml配置更加快捷 但不宜扩展 一.打开application.xml 1. ...

  2. php url地址栏传中文乱码解决方法集合

     php地址栏传中文$_GET下来后乱码,urlencode和urldecode,iconv,base64_encode等方法,整理基本是常用的了. php地址栏传中文$_GET下来后乱码,urlen ...

  3. c#自定义鼠标形状

    更改鼠标指针,需要使用到 Windows API: 1. 添加命名空间的引用: using System.Runtime.InteropServices; using System.Reflectio ...

  4. poj2139 Six Degrees of Cowvin Bacon

    思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  5. c# sqlserver连接字符串

    odbc: string cnnstring = @"Driver={SQL Server Native Client 11.0};Initial Catalog = sxquadb;ser ...

  6. Javascript中setTimeout()以及clearTimeout( )的使用

    setTimeout setTimeout( ) 是属于 window 的 method, 这是用来设定一个时间,时间到了, 就会执行一个指定的 方法.练习一:等候三秒才执行的 alert( )set ...

  7. socket是什么?协议栈操作的抽象

    http://www.cnblogs.com/airtcp/p/5230161.html TCP/IP只是一个协议栈,就像操作系统的运行机制一样,必须要具体实现,同时还要提供对外的操作接口.就像操作系 ...

  8. 浅析HashSet add() 方法存储自定义类型对象的过程

    一.自定义一个Student类 package date0504; public class Student { private String id; Student(String id){ this ...

  9. Apache安装和文件配置

    Apache和Tomcat的区别是:静态文件和动态页面,C++和Java的区别. 对比.

  10. vscode vue template 下 style 的样式自动提示 #bug 这个搞完vue语法esLint就又不好使了,ERR

    网上都是 "*.vue": "vue",改成"*.vue": "html" 就ok了   "files.ass ...