fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MAX 50010
  4.  
  5. typedef long long int ll;
  6.  
  7. struct info{
  8. ll x,y;
  9. }arr[MAX];
  10.  
  11. struct data_st{
  12. ll z;
  13. }temp;
  14.  
  15. bool operator < (struct data_st a, struct data_st b) {
  16. if(a.z > b.z) return true;
  17. else return false;
  18. }
  19.  
  20. bool cmp(struct info a, struct info b) {
  21. if(a.x < b.x) return true;
  22. if(a.x == b.x) {
  23. if(a.y < b.y) return true;
  24. else return false;
  25. }
  26. return false;
  27. }
  28.  
  29. int main(void){
  30. ll T,t,n;
  31. scanf("%lld",&T);
  32. for(t = 1; t <= T; t++){
  33. scanf("%lld",&n);
  34. for(ll i = 1; i <= n; i++){
  35. scanf("%lld %lld",&arr[i].x,&arr[i].y);
  36. }
  37. sort(arr+1,arr+1+n,cmp);
  38. priority_queue<struct data_st> PQ;
  39. ll counter = 1;
  40. temp.z = arr[1].y;
  41. PQ.push(temp);
  42. for(ll i = 2; i <= n; i++) {
  43. if(PQ.top().z < arr[i].x) {
  44. PQ.pop();
  45. temp.z = arr[i].y;
  46. PQ.push(temp);
  47. }
  48. else {
  49. counter++;
  50. temp.z = arr[i].y;
  51. PQ.push(temp);
  52. }
  53. }
  54. printf("Case %lld: %lld\n",t,counter);
  55. }
  56. return 0;
  57. }
  58.  
Time limit exceeded #stdin #stdout 5s 4252KB
stdin
Standard input is empty
stdout
Standard output is empty