Skip to content

Instantly share code, notes, and snippets.

@osjayaprakash
Created December 29, 2012 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osjayaprakash/4408234 to your computer and use it in GitHub Desktop.
Save osjayaprakash/4408234 to your computer and use it in GitHub Desktop.
BYTESE2, SPOJ
#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