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”.
思路:大水题,模拟即可。只不过又忘记开long long了结果卡在第五组数据。

#include <bits/stdc++.h>//第五组数据特别大,n是1e5,num_a[i]都是1e9,不知道为什么就是过不了这组
#define ll long long//额,找到问题了,又忘记开long long 了。。。using namespace std;
const int maxn = 1e5 + 5;int main()
{ll n;ll num_a[maxn];ll num_b[maxn];scanf("%d",&n);ll sum = 0;for(int i = 0;i < n;i++){scanf("%lld",&num_a[i]);sum += num_a[i];}for(int i = 0;i < n;i++){scanf("%lld",&num_b[i]);}sort(num_b,num_b + n);int Max1 = num_b[n - 1];int Max2 = num_b[n - 2];if(sum <= Max1 + Max2){printf("YES\n");}else printf("NO\n");return 0;
}

转载于:https://www.cnblogs.com/tomjobs/p/10617584.html

A - Greed CodeForces - 892A(水题)相关推荐

  1. codeforces 1041a(水题)

    http://codeforces.com/problemset/problem/1041/A(题目链接) There was an electronic store heist last night ...

  2. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  3. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

  4. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  5. 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)

    题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...

  6. Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  7. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

  8. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 1 /* 2 水题:ans = (1+2+3+...+n) * k - n,开long long 3 */ 4 #include <cstdio> 5 #include < ...

  9. Codeforces//Good Bye 2013//A. New Year Candles 水题

    第一次在Codeforces上提交题,全是英文,啊.应该是场比赛,WA了两次,丫的.哎,什么时候才能不做水题了呢.Happy New Year!Zhou Ping!努力奋斗! 题目链接:A. New ...

最新文章

  1. MongoDB的备份(mongodump)与恢复(mongorestore)
  2. Codeforces 524F And Yet Another Bracket Sequence 哈希
  3. C语言荣获2019年度最佳编程语言
  4. [BZOJ4815][CQOI2017]小Q的表格 数论+分块
  5. pandas 取excel 中的某一列_Excel快速分表(xlwings+pandas)
  6. LeetCode 2008. 出租车的最大盈利(DP)
  7. OpenShift 4 - 用内置的Prometheus监控应用
  8. 付出与收获对等的自然法则,执行力离开去做马上去做
  9. dongle 工具 蓝牙_CC2540 USB Dongle 蓝牙抓包分析仪使用教程
  10. 姚聪 旷世_首款国产豪华品牌大型SUV,汉龙旷世品质气场100分! - 快讯
  11. CSDN没有C币如何下载文章?
  12. duet display连接不上怎么办
  13. linux redis-连接命令
  14. getbook netty实战_Netty 实战(精髓)简介(Netty in Action)
  15. 种类并查集(POJ1703)
  16. 期刊、会议、SCI、EI、IEEE、CCF、ACM的区别与联系
  17. 【Unity】一个使用Dorween实现的血量条显示与血量变化
  18. 第六节课 大腿肌肉练习
  19. Android手机总内存和可用内存
  20. Jquery从入门到精通:二、选择器 1、准备篇 1)基础的基础:DOM模型

热门文章

  1. 树状数组基础原理与模板
  2. detectandcompute 图像尺寸太大_基于深度局部特征的图像检索
  3. 人类一败涂地做图教程_《人类一败涂地》形象绘画技巧图文指南
  4. centos8 安装docker_CentOS 8 安装 docker
  5. Python 基本输出
  6. IntelliJ IDEA开发工具安装Scala插件使用
  7. Hadoop生态系统的详细介绍
  8. c语言高函数正确形式,计算机二级C语言考点解析:函数
  9. java mvc增删改查_springmvc-CRUC增删改查
  10. 计算机右键管理显示没权限,解决右键 选择打开方式提示没有权限