内部赛 题目好像没有公开
很快就到考试周了!但是可怜的
平时过于认真训练,结果欠下了一大堆的作业,平时分岌岌可危!
![Big Q God Big Q God](http://www.bnuoj.com/v3/functions/latexrender/pictures/452ca35779267682d31b87da49b2a42e.png)
现在
从
时刻开始做作业,一共有
项作业,第
项作业会在
时刻布置下来(即当
时
可以做这一项作业),需要
的时间完成(假设当
时刻
选择做这一项作业,那么当
时
不能选择做其他作业)。
![BQG BQG](http://www.bnuoj.com/v3/functions/latexrender/pictures/70a7772303b35bfed91d3a9833df1fd6.png)
![t=0 t=0](http://www.bnuoj.com/v3/functions/latexrender/pictures/3e8f7b0adf6d7024b951f29a18225e4a.png)
![n n](http://www.bnuoj.com/v3/functions/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png)
![i i](http://www.bnuoj.com/v3/functions/latexrender/pictures/865c0c0b4ab0e063e5caa3387c1a8741.png)
![a_i a_i](http://www.bnuoj.com/v3/functions/latexrender/pictures/2aecb1dc57e87620a373d19b0a889efb.png)
![t geq a_i t geq a_i](http://www.bnuoj.com/v3/functions/latexrender/pictures/30348e9e8e458a0621934b38b7886e41.png)
![BQG BQG](http://www.bnuoj.com/v3/functions/latexrender/pictures/70a7772303b35bfed91d3a9833df1fd6.png)
![b_i b_i](http://www.bnuoj.com/v3/functions/latexrender/pictures/fe3e01a305f27284ff5115f4c5ea0fa4.png)
![t=x t=x](http://www.bnuoj.com/v3/functions/latexrender/pictures/cd7343af6659a2d87d45ec9c661a924c.png)
![BQG BQG](http://www.bnuoj.com/v3/functions/latexrender/pictures/70a7772303b35bfed91d3a9833df1fd6.png)
![t in [x,x+b_i) t in [x,x+b_i)](http://www.bnuoj.com/v3/functions/latexrender/pictures/889a8ee3f8dee1994d2e18bbddcc831c.png)
![BQG BQG](http://www.bnuoj.com/v3/functions/latexrender/pictures/70a7772303b35bfed91d3a9833df1fd6.png)
![BQG BQG](http://www.bnuoj.com/v3/functions/latexrender/pictures/70a7772303b35bfed91d3a9833df1fd6.png)
Input
第一行是一个正整数
,表示测试数据的组数,
![T(T leq 100) T(T leq 100)](http://www.bnuoj.com/v3/functions/latexrender/pictures/44f6cd6f2b99ad6cf53ee75ff7b1ed56.png)
对于每组测试数据,
第一行是一个正整数
,表示作业的数量,
![n(n leq 1000) n(n leq 1000)](http://www.bnuoj.com/v3/functions/latexrender/pictures/a40a5425c0aa5f64b063eedab701a105.png)
接下来
行,
![n n](http://www.bnuoj.com/v3/functions/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png)
每行包含两个整数
,表示作业布置的时刻和完成作业所需时间。
![a(0 leq a leq 1000000000),b(0 < b leq 1000000) a(0 leq a leq 1000000000),b(0 < b leq 1000000)](http://www.bnuoj.com/v3/functions/latexrender/pictures/ee9a302b9b88f993f2bf3e217b1f3870.png)
Output
对于每组测试数据,输出一个整数,表示最早完成所有作业的时刻。
#include <stdio.h> #include <algorithm> using namespace std; struct action{ int s;///布置的时间 int f;///需要的时间 }a[1005]; bool cmp(const action &a,const action &b) { if(a.s<=b.s) return true; else return false; } int main() { int t; scanf("%d",&t); while(t--) { int time=0;///当前时间 int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].s,&a[i].f); sort(a,a+n,cmp); for(int i=0;i<n;i++) { if(time<=a[i].s) { time=a[i].s+a[i].f; } else time=time+a[i].f; } printf("%d ",time); } return 0; }