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. appium+python自动化42-微信公众号

    前言 本篇介绍如何在微信公众号上自动化测试,以操作我的个人公众号:yoyoketang为例,没关注的,先微信关注了,再跟着操作 环境准备: python 3.6 appium 1.7以上版本 微信6. ...

  2. 过度使用DBLINK做系统集成会带来的问题

    过度使用DBLINK做系统集成会带来很多问题,问题主要由以下几点: 1. 大量消耗数据库资源: 本地系统每通过DBLINK链接远端系统一次,都会生成一个本地session,如本地session不退出或 ...

  3. [转]html 下拉框级联

    <html> <head> <title>html 下拉框级联</title> <meta charset="UTF-8"/& ...

  4. Notepad++ 删除空白行的方法(转)

    Notepad++ 是我特别喜欢的一款编程工具.在安装后就可以轻松使用了.Notepad++ 上提供了很多方便的插件以实现更多的扩展,当然自身已经比较强大好用了.如果你遇到文本中间有大量的空白行的话, ...

  5. centos自带的dvd中的官方base源,丢失了可以复制下面的内容

    /etc/yum.repos.d/CentOS-Base.repo文件中的内容,同样适用于centos6 [base]name=CentOS-$releasever - Basemirrorlist= ...

  6. OpenGL chapter2

    opengl: 图形硬件的一种软件接口:最大的优点:它的速度快于光线追踪器或软件渲染引擎. GLUT: AUX是OpenGL辅助函数库. 数据类型: GLboolean 位宽:1 GLbyte 8 G ...

  7. java编译器

    编译: .java变成.class        前端编译   Sun javac Eclipse ECJ .class变成机器码      运行期编译 等HostSpot VM c1,c2 .jav ...

  8. Linux 下的两种分层存储方案

    背景介绍 随着固态存储技术 (SSD),SAS 技术的不断进步和普及,存储介质的种类更加多样,采用不同存储介质和接口的存储设备的性能出现了很大差异.SSD 相较于传统的机械硬盘,由于没有磁盘的机械转动 ...

  9. Angular4之常用指令

    Angular4指令 NgIf <div *ngIf="false"></div> <!-- never displayed --> <d ...

  10. text-overflow:ellipsis ,溢出文本显示省略号

    text-overflow:ellipsis 对溢出文本显示省略号有两个好处, 一是不用通过程序限定字数 二是有利于SEO. 需要使用对对溢出文本显示省略号的通常是文章标题列表,这样处理对搜索引擎更友 ...