http://acm.uestc.edu.cn/#/contest/show/54

L - Lovely princess

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

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 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的更多相关文章

  1. cdoj第13th校赛初赛F - Fabricate equation

    http://acm.uestc.edu.cn/#/contest/show/54 F - Fabricate equation Time Limit: 3000/1000MS (Java/Other ...

  2. cdoj第13th校赛初赛H - Hug the princess

    http://acm.uestc.edu.cn/#/contest/show/54 H - Hug the princess Time Limit: 3000/1000MS (Java/Others) ...

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

  4. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  5. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  6. HZNU第十二届校赛赛后补题

    愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...

  7. 【魔改】hdu6325 多校赛3G xy排序凸包+llvector模板

    凸包算法前的预处理,可以极角排序,也可以按X,Y轴排序, 极角排序需要找到角落里的一个点,Xy轴排序要跑两遍凸包 而本题的要求只要一个上半凸包,并且有X轴从小到大以及字典序限制,完全符合xy排序,直接 ...

  8. 校赛F 比比谁更快(线段树)

    http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...

  9. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

随机推荐

  1. Web(click and script) 与 Web(HTTP/HTML)协议区别

    先从最简单的说明上来看, Web(HTTP/HTML):       Emulation of     communication between a    browser and Web Serve ...

  2. linux 重新设置memsql密码

    先登陆服务器,找到自己的my.cnf文件,通常会在 /etc目录下(如果不在,可以用find / -name my.cnf命令找一下),然后使用 vi my.cnf 命令编辑该文件(建议先备份),在[ ...

  3. ES之七:配置文件详解

    安装流程 http://www.elasticsearch.org/overview/elkdownloads/下载对应系统的安装包(我下载的是tar的),下载解压以后运行es根目录下bin目录的el ...

  4. [转]NSIS:常量大全

    原文链接 http://www.flighty.cn/html/bushu/20140915_251.html ;轻狂志www.flighty.cn ;运行后会在桌面生成NSIS常量大全.txt文件 ...

  5. 正则捕获的细节及replace分析

    1.var reg=/./与var reg=/\./的区别? 前者代表任意一个字符, 后者代表这个字符串中得有一个点 2.?的使用 如果单独的一个字符后面带? 代表1个或0个这个字符的出现: 列如: ...

  6. Linux下不同颜色文件的类型

    蓝色表示目录: 绿色表示可执行文件: 红色表示压缩文件: 浅蓝色表示链接文件:主要是使用ln命令建立的文件 灰色表示其它文件: 红色闪烁表示链接的文件有问题了: 黄色是设备文件,包括block, ch ...

  7. 学习URL地址(待整理)

    编程开发教程:http://www.runoob.com/ ElasticSearch教程:https://es.xiaoleilu.com/index.html 设计模式:http://www.cn ...

  8. 第15章 高并发服务器编程(2)_I/O多路复用

    3. I/O多路复用:select函数 3.1 I/O多路复用简介 (1)通信领域的时分多路复用 (2)I/O多路复用(I/O multiplexing) ①同一线程,通过“拨开关”方式,来同时处理多 ...

  9. 第3章 文件I/O(3)_内核数据结构、原子操作

    3. 文件I/O的内核数据结构 (1) 内核数据结构表 数据结构 主要成员 文件描述符表 ①文件描述符标志 ②文件表项指针 文件表项 ①文件状态标志(读.写.追加.同步和非阻塞等状态标志) ②当前文件 ...

  10. USB接口程序编写

    copy from http://blog.csdn.net/luckywang1103/article/details/12393889# HID是Human Interface Devices的缩 ...