Created
December 29, 2012 17:36
-
-
Save osjayaprakash/4408234 to your computer and use it in GitHub Desktop.
BYTESE2, SPOJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <vector> | |
#include <set> | |
#include <algorithm> | |
using namespace std; | |
#define PB push_back | |
typedef pair <int, bool> pii; | |
typedef unsigned long long ull; | |
typedef long long ll; | |
int comp( pii a , pii b){ | |
return a.first < b.first; | |
} | |
int main() | |
{ | |
int TC, N; | |
cin >> TC; | |
while(TC--){ | |
int res=0,s,e,prev=-1,cnt=0; | |
vector<pii> lst; | |
cin >> N; | |
for(int i=0;i<N;i++){ | |
cin >> s >> e; | |
lst.PB(pii(e,false)); | |
lst.PB(pii(s,true)); | |
} | |
sort(lst.begin(), lst.end(), comp); | |
// for(int i=0;i<lst.size();i++) cout << lst[i].first << ' ' << lst[i].second << ' '; cout << endl; | |
for(int i=0;i<lst.size();i++){ | |
if(lst[i].first != prev && res<cnt) | |
res=cnt; | |
if(lst[i].second == true){ | |
cnt++; | |
}else{ | |
cnt--; | |
} | |
prev = lst[i].first; | |
} | |
if(res<cnt) | |
res=cnt; | |
cout << res << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment