C. BQG's Approaching Deadline

C. BQG's Approaching Deadline

Time Limit: 2000ms
Memory Limit: 32768KB
64-bit integer IO format:  %lld      Java class name:  Main
很快就到考试周了!但是可怜的 Big \ Q \ God平时过于认真训练,结果欠下了一大堆的作业,平时分岌岌可危!
 
现在 BQGt=0时刻开始做作业,一共有 n项作业,第 i项作业会在 a_i时刻布置下来(即当 t \geq a_iBQG可以做这一项作业),需要 b_i的时间完成(假设当 t=x时刻 BQG选择做这一项作业,那么当 t \in [x,x+b_i)BQG不能选择做其他作业)。
 
BQG决定尽快解决掉所有作业,因此在完成所有作业之前他不会去做其他事情,他想知道最早在什么时刻能完成所有作业。

Input

第一行是一个正整数 T(T \leq 100),表示测试数据的组数,
 
对于每组测试数据,
 
第一行是一个正整数 n(n \leq 1000),表示作业的数量,
 
接下来 n行,
 
每行包含两个整数 a(0 \leq a \leq 1000000000),b(0 < b \leq 1000000),表示作业布置的时刻和完成作业所需时间。

Output

对于每组测试数据,输出一个整数,表示最早完成所有作业的时刻。

Sample Input

2
3
0 1
1 2
2 3
2
0 1
2 3

Sample Output

6
5

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
struct shu{
	int start;
	 int hour;
}h[10001];
bool  compare(struct shu a, struct shu b){
	return a.start<b.start;
}
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		cin>>n;
		int end=0;
	  for(int i=0;i<n;i++){
	  	scanf("%d %d",&h[i].start,&h[i].hour);
	  }
	  sort(h,h+n,compare);
	  for(int i=0;i<n;i++){
	  	end=max(end,h[i].start);
	  	end=end+h[i].hour;
	  }
	  cout<<end<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值