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 ;
}

最新文章

  1. python Django 进阶篇
  2. 25佳漂亮的结婚邀请 &amp; 婚礼请柬网站设计
  3. (转)ElasticSearch学习
  4. 让finder显示路径
  5. set_exception_handler 和 set_error_handler 函数
  6. HDU 2836 Traversal 简单DP + 树状数组
  7. vs2010旗舰版产品密钥
  8. CentOS中使用shell的命令补全
  9. vue+express之前后台分离博客
  10. Swoole笔记(五)
  11. nyoj888 取石子(九) 反Nimm博弈
  12. SQL语句异常导致项目报错
  13. ADC0832的应用
  14. 【AGC 002F】Leftmost Ball
  15. gevent模块学习(三)
  16. python基础-动态加载lazy_import(利用__import__)
  17. Ubuntu下配置eclipse
  18. js中对象转化成字符串、数字或布尔值的转化规则
  19. phpsso 与 Discuz!
  20. iOS开发ReactiveCocoa学习笔记(一)

热门文章

  1. 通过广播关闭应用程序(每个Activity)和连续点击两次返回键关闭应用程序
  2. 剑指Offer - 九度1505 - 两个链表的第一个公共结点
  3. 关于Ckpalyer播放器的MP4无法播放问题
  4. Python学习-day20 django进阶篇
  5. leetcode 179. 最大数 解题报告
  6. C++ 虚继承内存分配
  7. UVALive 4764 简单dp水题(也可以暴力求解)
  8. 块元素包裹img空隙问题
  9. javascript传递参数如果是object的话,是按值传递还是按引用传递?
  10. jstl标签forEach的用法--遍历java的集合