CSP 5-8 jump

Passed example; all WA on Codeforces
This commit is contained in:
cyp0633 2021-07-31 22:01:49 +08:00
parent 17ac94f962
commit fdb58f3278
1 changed files with 28 additions and 0 deletions

28
CSP-Training/5/8-jump.cpp Normal file
View File

@ -0,0 +1,28 @@
//CF1472C Long Jumps
#include <cstdio>
#include <iostream>
#include <map>
#include<cmath>
using namespace std;
int main()
{
int t, n;
map<long long, long long> dp;
long long int a, maxScore;
scanf("%d", &t);
while (t--)
{
dp.clear();
maxScore = -1;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lld", &a);
dp[i + a] = dp[i + a] > dp[i] + a ? dp[i + a] : dp[i] + a;
maxScore = maxScore > dp[i + a] ? maxScore : dp[i + a];
}
printf("%lld\n", maxScore);
}
return 0;
}