Codeforces 892 A.Greed
2 seconds
256 megabytes
standard input
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!
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.
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).
23 53 6
YES
36 8 96 10 12
NO
50 0 5 0 01 1 8 10 5
YES
44 1 0 35 2 2 3
YES
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相关推荐
- Codeforces 892 A Greed(水题)
题目链接:点击打开链接 题目大意:现在要把所有剩余的可乐倒进2个罐子里,问能不能实现? 代码如下: #include<iostream> #include<algorithm> ...
- Codeforces 892 B. Wrath (递推)(思维)
题意 每个人都有一个长度为 li 的武器,相邻的两个人之间距离为 1 ,同一时间所有人使用武器攻击左边的人,问最后存活下来的人数. 显然,最右侧的人一定是可以存活下来的. 我们维护一个 cntcnt ...
- [CodeForces 892A] Greed (Java中sort实现从大到小排序)
题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...
- Codeforces 892A. Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- A - Greed CodeForces - 892A(水题)
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can ...
- codeforces 博弈 Arena of Greed
题目描述: 思想: 首先,我们应该明确,如果一开始石子的数量为偶数,那么先手可以控制后手的选择,因为先手可以拿一个,那么后手也只能拿一个,先手的局面又变为偶数了.如果先手拿走一半后,石子的数量只剩下奇 ...
- codeforces 892A. Greed(水)
题意:现在有N瓶可乐,问有没有可能合到两个瓶子里面?第二行表示剩余可乐体积,第三行表示容量. 思路:维护一个最大值和一个次大值,判断总剩余可乐的体积跟这两个值之和的大小就OK. 我还智障的WA了一发, ...
- A. Arena of Greed
链接:https://codeforces.com/problemset/problem/1425/A Lately, Mr. Chanek frequently plays the game Are ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
最新文章
- 过拟合、欠拟合与正则化
- 企业实施SAP项目的得与失
- 前端学习(2082):const得使用和注意点
- k均值例子 数据挖掘_【十大经典数据挖掘算法】k-means
- 4k*1芯片 计算机组成,计算机组成原理的大神们能不能帮忙做几道题啊
- 【python】编程语言入门经典100例--23
- SOSO移动服务大厅项目分析
- 2.3 响应文件(Response File)
- (UTF-8)ASP汉字转拼音函数(附Access数据库)
- HDOJ 5100 Chessboard 构造
- PCI设备初始化(一)
- 光学基础知识:焦点、弥散圆、景深 焦深
- 畅言评论没有头像的临时解决方法
- CS5268/CS5265/CS5266 Type-C转HDMI设计方案|替代CS5268/CS5265/CS5266芯片|GSV2201可完全替代兼容CS5268/CS5265/CS5266
- Illum voluptatum suscipit dolor tempore est sequi.
- 分布式缓存Redis 面试突击
- 第三篇 第二章消防给水(三)
- 硕盟type c六合一拓展坞|苹果电脑转换器
- NLP中的alignment 对齐 的理解
- 也许你的账号密码就是这样泄露了!
热门文章
- 与君共品代码: Spelling Corrector
- 通过 BTC Relay 来实现链与链的连接
- 25A - IQ test
- 华科学子连续三年入选华为 “天才少年” !毕业生获201万最高档年薪!
- B/S三层架构[转载]
- 测试面试题——三角形
- YOUTH(年轻)——Samuel Ullman(塞缪尔·乌尔曼)
- ecshop2.7.3+windows10(64bit)+phpstudy2018(php5.4.45+apache+mysql)
- MTBD 电影市场分析
- 梦幻西游新区服务器维护,梦幻西游2月新区2018 2月新开服务器介绍