cdoj第13th校赛初赛L - Lovely princess
http://acm.uestc.edu.cn/#/contest/show/54
L - Lovely princess
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
There are n jobs you need to complete. However, complete the ith job you capability must be no less than vi. If you have completed the ith job, your capability will increase ai.
Then the question is coming, what is the minimum initial capability value if you are required to complete all of the n jobs.
Note that there is no restriction on the order you complete them. That is to say, you can decide the order by your own.
Input
The first line contains a single integer n, which is the number of jobs you need to complete.
Then each of the following n lines contains 2 integers vi and ai, which are described above.
1≤n≤1000,0≤vi≤1000000,0≤ai≤1000
Output
Print the answer in one line.
Sample input and output
| Sample Input | Sample Output |
|---|---|
1 |
2 |
思路:运用贪心策略,对v排序。(之前一直tle,因为读错了题,以及v是消耗值。。。囧)
官方题解:

代码:
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector> using namespace std; #define PI acos(-1.0)
#define EPS 1e-10
#define lll __int64
#define ll long long
#define INF 0x7fffffff const int N=; struct node{
int v,a;
}yu[N];
int n,ans,cans; bool cmp(const node &r1,const node &r2){
return r1.v<r2.v;
} int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
int t1,t2;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d %d",&yu[i].v,&yu[i].a);
}
sort(yu,yu+n,cmp);
for(int i=;i<n;i++){
if(cans<yu[i].v){
ans+=yu[i].v-cans;
cans=yu[i].v;
}
cans+=yu[i].a;
}
printf("%d\n",ans);
return ;
}
cdoj第13th校赛初赛L - Lovely princess的更多相关文章
- cdoj第13th校赛初赛F - Fabricate equation
http://acm.uestc.edu.cn/#/contest/show/54 F - Fabricate equation Time Limit: 3000/1000MS (Java/Other ...
- cdoj第13th校赛初赛H - Hug the princess
http://acm.uestc.edu.cn/#/contest/show/54 H - Hug the princess Time Limit: 3000/1000MS (Java/Others) ...
- cdoj第13th校赛初赛A - AC Milan VS Juventus 【枚举】
http://acm.uestc.edu.cn/#/contest/show/54 A - AC Milan VS Juventus Time Limit: 3000/1000MS (Java/Oth ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
- HZNU第十二届校赛赛后补题
愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...
- 【魔改】hdu6325 多校赛3G xy排序凸包+llvector模板
凸包算法前的预处理,可以极角排序,也可以按X,Y轴排序, 极角排序需要找到角落里的一个点,Xy轴排序要跑两遍凸包 而本题的要求只要一个上半凸包,并且有X轴从小到大以及字典序限制,完全符合xy排序,直接 ...
- 校赛F 比比谁更快(线段树)
http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
随机推荐
- HDU 1116 Play on Words(并查集和欧拉回路)(有向图的欧拉回路)
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Ubuntu安装配置串口通讯工具minicom&&cutecom
原帖地址:https://blog.csdn.net/gatieme/article/details/45310493 2017-04-07更新 发现新的工具gtkterm全名叫serial port ...
- 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #21FUSE
HACK #21FUSE 本节将介绍使用用户进程的文件系统框架—FUSE.FUSE概要FUSE(Filesystem in Userspace,用户空间文件系统),是用来生成用户空间的一般进程的框架. ...
- 基于Linux的Samba开源共享解决方案测试(五)
对于客户端的网络监控如图: 双NAS网关50Mb码率视音频文件的稳定写测试结果如下: 100Mb/s负载性能记录 NAS网关资源占用 稳定写 稳定写 CPU空闲 内存空闲 网卡占用 NAS1 16个稳 ...
- Java并发编程学习路线(转)
以前特地学过并发编程,但是没怎么学进去,不太喜欢.最近发现,作为一个资深工程师,却没有完整深入系统的学习过,而反是现在的BAT大并发是必须的,感觉甚是惭愧. 故找了一片学习文章,如下,准备集中一段时间 ...
- java技术-重点方向
多线程 锁 事务 缓存 hashmap 并发编程
- python装饰器(docorator)详解
引言: 装饰器是python面向对象编程三大器之一,另外两个迭代器.生成器只是我现在还没有遇到必须使用的场景,等确实需要用到的时候,在补充资料:装饰器在某些场景真的是必要的,比如定义了一个类或者一个函 ...
- 使用Larave5.6l提交POST请求出现The page has expired due to inactivity错误
使用Larave5.6l提交POST请求出现The page has expired due to inactivity错误 一般是由于没有添加 csrf造成的 在表单下面的 第一个行 添加如下代码即 ...
- 使用amaze ui模板全过程
amaze ui基于gulp构建,所以现在安装gulp需要的环境,gulp使用npm安装,npm基于node.js 所以一切从node.js开始 1 下载对应的node.js 打开 https://n ...
- zabbix自动发现与监控内存和CPU使用率最高的进程,监测路由器
https://cloud.tencent.com/info/488cfc410f29d110c03bcf0faaac55b2.html (未测试) https://www.cnblo ...