Codeforces 1472C - Long Jumps Solution

  Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh 

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. main()
  4. {
  5. int n,i,t,s,j;
  6. cin>>t;
  7. while(t--)
  8. {
  9. cin>>n;
  10. int a[n+1],r=0;
  11. for(i=1; i<=n; i++)
  12. cin>>a[i];
  13.  
  14. for(i=n; i>0; i--)
  15. {
  16. if((i+a[i])<=n)
  17. a[i]+=a[i+a[i]];
  18.  
  19. r=max(r,a[i]);
  20. }
  21. cout<<r<<endl;
  22.  
  23. }
  24. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.