fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n;
  7. cin>>n;
  8. int a[n],i,l,r;
  9. for(i=0;i<n;i++)
  10. cin>>a[i];
  11. int jumps[n+1]={0};
  12. for(i=1;i<=n;i++){
  13. l=max(1,i-a[i-1]);
  14. r=min(n,i+a[i-1]);
  15. jumps[l]=max(jumps[l],r-l);
  16. }
  17. i=jumps[0];
  18. int score=0;
  19. while(i<n-1){
  20. i+=jumps[i];
  21. score++;
  22. }
  23. cout<<score;
  24. return 0;
  25. }
Time limit exceeded #stdin #stdout 5s 4504KB
stdin
3
1 2 1
stdout
Standard output is empty