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)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
随机推荐
- 2018-2019 20165226 Exp6 信息搜集与漏洞扫描
2018-2019 20165226 Exp6 信息搜集与漏洞扫描 目录 一.实验内容说明及基础问题回答 二.实验过程 Task1 各种搜索技巧的应用 检测特定类型的文件 搜索网址目录结构 trace ...
- Source引擎多人模式网络同步模型
转自:http://gad.qq.com/program/translateview/7168875 Source引擎的多人游戏使用基于UDP通信的C/S架构.游戏以服务器逻辑作为世界权威,客户端和服 ...
- Java 迭代器 工具类
迭代器:Iterator接口 //获取集合中的对象Iterator<E> iterator() interface Iterator { boolean hasNext(); Object ...
- 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #21FUSE
HACK #21FUSE 本节将介绍使用用户进程的文件系统框架—FUSE.FUSE概要FUSE(Filesystem in Userspace,用户空间文件系统),是用来生成用户空间的一般进程的框架. ...
- 启动 node 文件时附带参数
cmd: node app.js hello app.js var args = process.argv; console.log(args);//[ 'C:\\Program Files\\nod ...
- Django Middleware 之 SessionMiddleware
Django版本:1.7.11 先放源码: class SessionMiddleware(object): def __init__(self): engine = import_module(se ...
- Executor框架(二)Executor 与 ExecutorService两个基本接口
一.Executor 接口简介 Executor接口是Executor框架的一个最基本的接口,Executor框架的大部分类都直接或间接地实现了此接口. 只有一个方法 void execute(Run ...
- 使用 SignalR与SSE(Sever sent event)向客户端推送提示信息
最近有个项目想把c/s的代码转成mvc的,这听起来并不困难. 如果UI和业务逻辑良好分离了的话,不会花太多的功夫,应该多数的内容都能重复利用. 但在实际的操作过程中,发现业务逻辑代码和UI提示全是混在 ...
- uva-539-枚举
题意: 给你一个无向图,找最长路. 俩份代码,感觉map[][]简单易懂啊 #include<stdio.h> #include<iostream> #include<s ...
- 配置文件 .properties 的使用。
在代码中使用 @Controller public class IndexController { @Value("${CONTENT_LUNBO_ID}") private Lo ...