Monday, 13 August 2012

Spoj 3921. The Great Ball Solution

#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>

using namespace std;

#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
#define MX 10000010
#define MOD 1000000007


struct Z{
    int time;
    bool chk;
    bool operator < (const Z &p) const{
    if(time==p.time)
        return chk<p.chk;
    return time>p.time;
    }
};


main()
{
    int t,n,tm,i;
    cin>>t;
    while(t--)
    {
        priority_queue<Z>pq;
        Z TM;
        int cnt=0, mx=0;
        cin>>n;
        for(i=0;i<n*2;i++)
            {
                cin>>tm;
                TM.time=tm;
                if(i%2==0)
                    TM.chk=true;
                else
                    TM.chk=false;
                pq.push(TM);
            }

        for(i=0;i<n*2;i++)
            {
                TM=pq.top();

                if(TM.chk)
                    {
                        cnt++;
                        mx=max(cnt,mx);
                    }
                else
                    cnt--;
                pq.pop();
            }
        //cout<<pq.top().time<<endl;
        cout<<mx<<endl;
    }
}

No comments:

Post a Comment