14 Mar 2013

Jurassic Park_solved


/*
CODECHEF
Problem code: NI01

*/


#include<stdio.h>
#include<stdlib.h>
int n[100002];
int main()
 {
    int t,p,r,k,i,m,q,l,c;
    scanf("%d",&t);
    while(t--) 
     {
       scanf("%d%d%d%d%d%d",&n[0],&m,&q,&p,&r,&k);
       l=0;
       for(i=0;i<=k;i++)
         {
           if(m&&i&&!(i%r)) 
             {
               m--;
               q++;
             }
           if(n[i]&&q) 
             {
               c = n[i]<q ? n[i] : q;
               n[i]-=c;
               q-=c;
               if((i+p)<=k) 
                 {
                  n[i+p]+=c;
                  l+=c;
                 }
             }
           n[i+1]+=n[i];
        }
     printf("%d %d %d %d\n",n[k],l,m,q);
    if(t) memset(n,0,4*(k+2));
   }
  return 0;
} 
 
 

Categories: , , ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger