Codeforces 1472C - Long Jumps Solution
Solution in C++:
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- main()
- {
- int n,i,t,s,j;
- cin>>t;
- while(t--)
- {
- cin>>n;
- int a[n+1],r=0;
- for(i=1; i<=n; i++)
- cin>>a[i];
- for(i=n; i>0; i--)
- {
- if((i+a[i])<=n)
- a[i]+=a[i+a[i]];
- r=max(r,a[i]);
- }
- cout<<r<<endl;
- }
- }
No comments