Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Friday, May 23, 2014

PAML-Popoye and the magical land

Popoye and the magical land 

given below c code for pamlspoj or Popoye and the magical land spoj.
question is simple but if you still feel problem then ask me @ raj.nishant360@gmail.com
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int t,k;
 scanf("%d",&t);
 for(k=1;k<=t;k++)
 {
  int n,temp;
  vector<int>v;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
   scanf("%d",&temp);
   v.push_back(temp);
  }
  int height=0,max_h=-1,count=-1;
  sort(v.begin(),v.end());
  bool status = true;
  while(status)
  {
   status = false;
   for(int i=0;i<n;i++){
    if(v[i]!=-1)
     status=true;
   }
   count++;
   for(int i=0;i<n;i++)
   {
    if(v[i]>=height)
    {
     height++;
     v[i]=-1;
    }
   }
   if(max_h<height)
    max_h=height;
   height = 0;
  }
  printf("Case #%d: %d %d\n",k,count,max_h);
 }
 return 0;
}