博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A. Greed CodeForces - 892A
阅读量:4045 次
发布时间:2019-05-25

本文共 1547 字,大约阅读时间需要 5 分钟。


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 ≤ 10^9) — volume of remaining cola in cans.

The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 10^9) — 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".

题意:

其实这个题意是比较简单的,要求第一行给出一个整数n表示n罐可乐,第二行是n个数来表示n个罐中剩余的可乐的体积,第三行是n个数来表示这n个罐的容量。然后来判断这些剩余的所有可乐能否全部装到n个罐中任选的两个罐中。

思路:

计算出所有剩余可乐的体积,然后与n个罐中体积最大的两个罐来比较就可以了。

代码:

#include
#include
using namespace std;int main(){ long long i,n,x,y,sum=0; long long max1=0,max2=0; //max1来存放最大的可乐罐的体积,max2来存放第二大的可乐罐体积 scanf("%lld",&n); for(i=0;i
=max1) { max2=max1; max1=y; } else if(y>max2) { max2=y; } } if(sum <= max1+max2) printf("Yes\n"); else printf("No\n"); return 0;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的文章
yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。
查看>>
yuv420 format
查看>>
yuv420 还原为RGB图像
查看>>
LED恒流驱动芯片
查看>>
驱动TFT要SDRAM做为显示缓存
查看>>
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt 创建异形窗体
查看>>
可重入函数与不可重入函数
查看>>
简单Linux C线程池
查看>>
内存池
查看>>
输入设备节点自动生成
查看>>
GNU hello代码分析
查看>>
Qt继电器控制板代码
查看>>
wpa_supplicant控制脚本
查看>>
gstreamer相关工具集合
查看>>
RS232 四入四出模块控制代码
查看>>
linux 驱动开发 头文件
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>