Saturday, March 29, 2014

codechef March Challenge 2014 Walk solution

codechef March Challenge 2014 Walk: http://www.codechef.com/MARCH14/problems/WALK , http://www.codechef.com/problems/WALK

codechef March Challenge 2014 Walk editorial: http://discuss.codechef.com/questions/39939/walk-editorial

codechef March Challenge 2014 Walk solution: http://ideone.com/HuRk2m


#include <iostream>
#include <cstdio>
using namespace std;

int main() {
 int t, n, w, max, in, step;
 scanf("%d", &t);
 while(t--) {
  step=max=in=0;
  scanf("%d", &n);
  for(int i=0; i<n; i++) {
   scanf("%d", &w);
   if(w>step) step=max=w, in=i;
   step--;
  }
  printf("%d\n", max+in);
 }
 return 0;
}


No comments:

Post a Comment