杭电 1025

using namespace std;
int arr1[500001];
set<int> s;
typedef set<int>::iterator IT;
int main()
{
 int n;int CNT=0;
 while(cin>>n)
 {
  for(int i=0;i!=n;++i)
  {
   int a,b;cin>>a>>b;
   arr1[a]=b;
  }
  s.clear();
  s.insert(0);s.insert(INT_MAX);
  int result=0;
  for(int i=n;i>=1;--i)
  {
    s.insert(arr1[i]);
    IT it=--s.find(arr1[i]);
    if(it==s.begin())
     result++;
    else
     s.erase(it);

  }
  cout<<"Case "<<++CNT<<":"<<endl;
  if(result==1)
   cout<<"My king, at most 1 road can be built."<<endl<<endl;
  else
   cout<<"My king, at most "<<result<<" roads"<<" can be built."<<endl<<endl;
 }
    return 0;
}

你可能感兴趣的:(杭电 1025)