codeforces - 920B(贪心)

B. Tea Queue

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently n students from city S moved to city P to attend a programming camp.

They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.

i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.

For each student determine the second he will use the teapot and get his tea (if he actually gets it).

Input

The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000).

Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students.

Then n lines follow. Each line contains two integer liri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.

It is guaranteed that for every  condition li - 1 ≤ li holds.

The sum of n over all test cases doesn't exceed 1000.

Note that in hacks you have to set t = 1.

Output

For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.

Example

input

Copy

2
2
1 3
1 4
3
1 5
1 1
2 3

output

Copy

1 2
1 0 2 

Note

The example contains 2 tests:

  1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second.

  2. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea

  3. 这道题目的的难度个人认为是翻译,主要本人英语水平有限。题意是:首先由t组输入,在输入n表示有几人,在下面的n行表示每个人排队的时间li和每个可以等到的时间r这里强调是等到时间而不是可以等多长时间如果这个人在r时间以后还等不到那他就喝不到茶叶,还有最重要的一点输出的是每个人在第几秒喝到了茶,如果喝不到就输出0;其实可以算个模拟题吧,先排序,然后不断更新时间与时间进行比较,最后开一个数组来存每个id的喝茶时间,然后输出。

  4. 代码如下:

  5. #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #define pi acos(-1)
    using namespace std;
    typedef long long ll;
    const int maxn=1e3+10;
    const int INF=0x3f3f3f3f;
    const double EPS = 1e-10;
    inline int read(){
        int ret=0,f=0;char ch=getchar();
        while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
        while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
        return f?-ret:ret;
    }
    int t; 
    struct node{
    	int l,r;
    	int id;
    }p[maxn];
    bool cmp(node x,node y){
    	if(x.l==y.l) return x.id>t;
    	int n;
    	while(t--){
    		cin>>n;
    		for(int i=1;i<=n;i++){
    			cin>>p[i].l>>p[i].r;
    			p[i].id=i;
    		}
    		sort(p+1,p+n+1,cmp);
    		a[p[1].id]=p[1].l;
    		int ans = a[p[1].id];
    		for(int i=2;i<=n;i++){
    			if(p[i].r<=ans){
    				a[p[i].id]=0;
    			}else{
    				if(p[i].l>ans){
    					ans=p[i].l;
    					a[p[i].id]=ans;
    				}else if(p[i].l<=ans){
    					ans++;
    					a[p[i].id]=ans;	
    				}
    			}
    		}
    		for(int i=1;i
    好好努力,记录生活点点滴滴,相信会越来越好。

你可能感兴趣的:(cf题,acm题目)