Thursday 10 May 2012

UVa 11776 Oh Your Royal Greediness! Solution


#include<iostream>
using namespace std;
int main()
{
    long long n,i,s,e,a[2000],b[2000],max,cnt1,cnt2,j,t=1;
    while(cin>>n)
    {
        if(n==-1) return 0;
        for(i=1;i<=n;i++)
        {
            cin>>s>>e;
            a[i]=s;
            b[i]=e;
        }
        max=0;
        for(i=1;i<=n;i++)
        {
            cnt1=0;
            cnt2=0;
            for(j=1;j<=n;j++)
            {
                if(a[i]>=a[j] && a[i]<=b[j])
                cnt1++;
                if(b[i]>=a[j] && b[i]<=b[j])
                cnt2++;
            }
            if(cnt1>max)    max=cnt1;
            if(cnt2>max)    max=cnt2;
        }
    cout<<"Case "<<t<<": "<<max<<endl;
    t++;

    }
}

1 comment:

  1. It would be a great help to us, if we get a little explanation about this code.

    ReplyDelete