Advertisement
Manioc

SPREAD2 - adjust

Oct 12th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX 1000007
  3.  
  4. using namespace std;
  5.  
  6. long long arr[MAX];
  7. int main(){
  8.     int q; scanf("%d", &q);
  9.     int idx, day, n;
  10.     long long pick;
  11.     long long acum;
  12.     while(q--){
  13.         scanf("%d", &n);
  14.         for(int i = 0; i < n; i++) scanf("%lld", &arr[i]);
  15.  
  16.         idx = 1;
  17.         day = 0;
  18.         pick = arr[0];
  19.         while(idx < n){
  20.             acum = 0;
  21.             //cout << "ini ->" << idx << " " << pick << endl;
  22.             for(long long i = pick; idx < n && i > 0; i--){
  23.                 acum += arr[idx++];
  24.             }
  25.             //cout << "fim -> " << idx << " " << acum << endl;
  26.             pick += acum;
  27.             day++;
  28.         }
  29.         printf("%d\n", day);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement