toj 2867. Picking Problem

On holiday, Kandy happens to come to a square. People there are playing different kinds of games. Each game has a start time and a lasting duration. Two or more games may carry on at the same time. Kandy likes the games so much that he wants to take apart in as many as possible games. Given the list of all the games, can you help him to calculate the maximum number of games that he can take.

Input

There are several test cases. The first line of each test case is a single integer N, which is the total number of the games (1 ≤ N ≤ 10000). It's followed by N lines, each line has two integers, S and D, and S is the start time of the ith game, and D is the game's duration (0 ≤ S ≤ 10000, 1 ≤ D ≤ 1000).

The last case is followed by a single integer 0.

Output

For each case, output one line with a single integer M, which is the maximum number of games that Kandy can take.

Sample Input

5
0 3
5 10
9 2
3 4
2 2
0

Sample Output

3

#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int s,d;
}c[10001];
int cmp(node a,node b){
return a.d<b.d;
}
int main(){
int n,a,b,r,j;
while(cin>>n&&n){
r=1;
for(int i=0;i<n;i++){
cin>>a>>b;
c[i].s=a;
c[i].d=b+a;
}
sort(c,c+n,cmp);
//for(int i=0;i<n;i++)
// cout<<c[i].s<<" "<<c[i].d;
//cout<<endl;
j=0;
for(int i=1;i<n;i++){
if(c[i].s>=c[j].d){
r++;
j=i;
}
}
cout<<r<<endl;
}
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值