codeforces 892A - Greed - [超级大水题][O(n)数组最大和次大]

题目链接:https://cn.vjudge.net/problem/CodeForces-892A

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

Example

Input

23 53 6

Output

YES

Input

36 8 96 10 12

Output

NO

Input

50 0 5 0 01 1 8 10 5

Output

YES

Input

44 1 0 35 2 2 3

Output

YES

贼JR的水,根本不需要题解……

只是想贴一个记录一下O(n)得到数组内最大和次大的for循环代码,免得以后什么时候脑抽忘记了下不出来僵掉了……

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
int main()
{
    scanf("%d",&n);
    LL sum=0;
    for(int i=1,tmp;i<=n;i++)
    {
        scanf("%d",&tmp);
        sum+=tmp;
    }
    LL max1=-1,max2=-2;
    for(int i=1,tmp;i<=n;i++)
    {
        scanf("%d",&tmp);
        if(max2<=max1 && max1<=tmp) max2=max1,max1=tmp;
        else if(max2<tmp && tmp<=max1) max2=tmp;
    }
    if(max1+max2 >= sum) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
时间: 2024-08-07 02:21:05

codeforces 892A - Greed - [超级大水题][O(n)数组最大和次大]的相关文章

UVA12709 Falling Ants(超级大水题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4447 Ps:此题超级水,但是光看题目就会被吓一跳.确实题目很长,不过有用的语句少之又少,介绍一大堆与AC没有半毛钱关系的东西,汗颜. 此题告诉我们题目长不一定是最难得题,反而有时候是最简单的题,就看你有

UVA 100 The 3n + 1 problem(超级大水题)

The 3n + 1 problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you

Compote CodeForces - 746A 又是一个大水题~~~~~

Compote CodeForces - 746A 直接按比例找就行. 最初WA的代码:  QAQ  写的复杂... #include <stdio.h>#include<stdlib.h>int main(){    int a,b,c,i,j,k,ans;    scanf("%d%d%d",&a,&b,&c);    i=a;    j=b/2;    k=c/4;    if(i==0||j==0||k==0)        pr

hdu 1229 超级大水题

Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description 读入两个小于10000的正整数A和B,计算A+B.需要注意的是:如果A和B的末尾K(不超过8)位数字相同,请直接输出-1. Input 测试输入包含若干测试用例,每个测试用例占一行,格式为"A B K",相邻两数字有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.

BNU 斩(超级大水题)

L. 斩 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status PID: 29379 在电影里面,我们经常可以看到武士们拔出刀,然后一刀斩下去,结果------------一张纸片被砍成了两半,囧---- 而在本题中,我们需要计算一下被斩下去较小的那一部分的面积. 我们假设纸片是矩形的,平行于坐标轴的,武士砍纸片的轨迹是一条直

Pythagorean Triples CodeForces - 707C 推理题,大水题

给定一个数n(1 <= n <= 1e9),判断这个数是否是一个直角三角形的边长,如果是,则输出另外两条边(1 <= x <= 1e18),否则输出-1. 参考题解:http://blog.csdn.net/harlow_cheng/article/details/69055614 首先,当n <= 2 的时候无解,其他时候都有解 假设n是直角边,a是斜边,则n^2 + b^2 = a^2; n^2 = (a + b)*(a - b); ①假设n是偶数,则另(a - b) =

PAT甲题题解-1101. Quick Sort (25)-大水题

快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着循环一次,统计出代码中的minnum和maxnum即可,注意最后一定要输出'\n',不然第三个测试会显示PE,格式错误. #include <iostream> #include <cstdio> #include <algorithm> #include <map&

大水题(water)

题目描述dzy 定义一个 $n^2$ 位的数的生成矩阵 $A$ 为一个大小为 $n \times n$ 且 Aij 为这个数的第 $i \times n+j-n$ 位的矩阵.现在 dzy 有一个数 $n^2$ 位的数 k,他想知道所有小于等于 k 的数的 $n \times n$ 生成矩阵有多少种.(如果不足 $n^2$ 位则补前缀零)输入输出格式输入格式第一行一个数 $n$,第二行一个 $n^2$ 位的数 $k$输出格式仅一行表示答案,答案可能很大,你只需输出答案对 $10^9 + 7$ 取模

[补档]两个奇怪的大水题

导引 这是两道由OSU(貌似是一个我没有听说过的游戏)引申出的大水题(淼到不行啊喂),壹佰万行代码哦. T1 OSU! 题目 osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n的01串.在这个串中连续的 X个1可以贡献X^3 的分数,这x个1不能被其他连续的1所包含(也就是极长的一串1,具体见样例解释) 现在给出n,以及每个操作的成功率,请你输出期望分数,输出四舍五