2894. Meetings

来源:互联网 发布:sql 存储过程 编辑:程序博客网 时间:2024/06/07 16:41

There are several meeting rooms in Tianjin University. Since there are a lot of new students registering at the beginning of the term, the directors of school have scheduled many meetings to discuss upcoming issues. Suppose there are N meetings in total. The i-th meeting starts at time si and ends at time ei. Consider the j-th meeting can be held immediately after the i-th meeting in the same meeting room. Then we must have sj ≥ ei. In order to minimize usage of resources, the directors of school has asked you to write a program that calculates the minimum number of meeting rooms required for the whole meetings.

Input

There are several test cases in the input data. The first line contains the number of test cases. The first line contains a positive integer N (1 ≤ N ≤ 105) denoting the number of meetings. Then there are N lines, and the i-th line contains si and ei, (1 ≤ si < ei ≤ 109) denoting the start time and the end time of i-th meeting.

Output

Output the minimum number of meeting rooms required for the whole meetings.

Sample Input

221 33 533 51 44 5

Sample Output

12

Hint: In the second sample input, we can arrange the meeting like this to minimize the number of meeting rooms required:
Room A: (1, 4) (4, 5)
Room B: (3, 5)


#include<iostream>#include<algorithm>using namespace std;const int num=100000;int a[num],b[num];int main(){int t,n;cin>>t;while(t--){cin>>n;for(int i=0;i<n;i++){cin>>a[i]>>b[i];}sort(a,a+n);sort(b,b+n);int i=0,j=0;int ans=0;while(i<n){if(a[i]>=b[j]){i++;j++;}else{i++;ans++;}}cout<<ans<<endl;}return 0;}

0 0
原创粉丝点击