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

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[100010], b[100010], sum;int main()
{cin >> n;for (int i = 1; i <= n; i++){long long t;cin >> t;sum += t;}for (int i = 1; i <= n; i++)cin >> b[i];sort(b + 1, b + 1 + n);if (sum <= b[n] + b[n - 1])puts("YES");elseputs("NO");return 0;
}

转载于:https://www.cnblogs.com/zbtrs/p/7858282.html

Codeforces 892 A.Greed相关推荐

  1. Codeforces 892 A Greed(水题)

    题目链接:点击打开链接 题目大意:现在要把所有剩余的可乐倒进2个罐子里,问能不能实现? 代码如下: #include<iostream> #include<algorithm> ...

  2. Codeforces 892 B. Wrath (递推)(思维)

    题意 每个人都有一个长度为 li 的武器,相邻的两个人之间距离为 1 ,同一时间所有人使用武器攻击左边的人,问最后存活下来的人数. 显然,最右侧的人一定是可以存活下来的. 我们维护一个 cntcnt ...

  3. [CodeForces 892A] Greed (Java中sort实现从大到小排序)

    题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...

  4. Codeforces 892A. Greed

    A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. A - Greed CodeForces - 892A(水题)

    Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can ...

  6. codeforces 博弈 Arena of Greed

    题目描述: 思想: 首先,我们应该明确,如果一开始石子的数量为偶数,那么先手可以控制后手的选择,因为先手可以拿一个,那么后手也只能拿一个,先手的局面又变为偶数了.如果先手拿走一半后,石子的数量只剩下奇 ...

  7. codeforces 892A. Greed(水)

    题意:现在有N瓶可乐,问有没有可能合到两个瓶子里面?第二行表示剩余可乐体积,第三行表示容量. 思路:维护一个最大值和一个次大值,判断总剩余可乐的体积跟这两个值之和的大小就OK. 我还智障的WA了一发, ...

  8. A. Arena of Greed

    链接:https://codeforces.com/problemset/problem/1425/A Lately, Mr. Chanek frequently plays the game Are ...

  9. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

最新文章

  1. java -d32_java11教程--JDK 10删除和不推荐的功能和选项-2
  2. vuejs学习笔记(1)--属性,事件绑定,ajax
  3. python好用-Python有哪些常见的、好用的爬虫框架?
  4. JavaScript的9个陷阱及评点
  5. JAVA基础实例(一)
  6. 吐血整理!10 个机器学习教程汇总,爱可可推荐!
  7. 如何在 Mac 上的“快速查看”中查看和编辑文件
  8. Origin绘制热力图
  9. 计算机网络学习笔记--网络层知识点整理
  10. Apache Calcite官方文档中文版-概览-1.背景
  11. Material UI 4.10 Skeleton 骨架
  12. MongoDB的江湖传说
  13. 操作系统课程设计(linux操作系统)
  14. 企业信息管理系统汇总
  15. 软件测试及标准(基于ISO/IEC/IEEE 29119系列)
  16. 【THUSC2016】蒟蒻的酱油记
  17. JPopupButton
  18. Uniapp苹果登录sign in Apple
  19. 潮汐监测站点 api数据接口
  20. 最新YGBOOK小说站源码/全自动采集+已修BUG

热门文章

  1. ---------------------------SQL之机选大乐透,双色球算法-----------------------------
  2. Android获取手机中的所有音乐地址
  3. 【深度学习学习笔记】数值计算——矩阵
  4. mysql后门_运用Mysql语句生成后门具体办法
  5. 重复字符串的处理问题
  6. 尔雅云Wi-Fi云计费平台应用白皮书_V1.3.2版本
  7. LINUX Beyond-Compare 4
  8. 两阶段目标检测重要论文总结
  9. 图纸设计管理平台,彩虹图纸管理软件设计管理功能
  10. oracle form set_block_property,ORACLEERP开发基础之OracleForms基础(二)