Hint : performing a jump on index will skip the elements i , i+1 , ... , i+d-1.
Solution: jump operation will skip a continuous subarray from the array , so the final score will be .
c = \sum\limits_{i=1}^{n} a_i the sum of skipped subarray.
since we need to maximize the score it's optimal to skip the subarray which has the smallest sum, defining the sum of an empty subarray .
you can find the min subarray sum using kadane's algorithm.
Time complexity : .
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define F first
#define S second
using namespace std;
const int N = 2e5 + 1;
const int M = 1e9 + 7;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tc = 1;
cin>>tc;
while(tc--)
{
int n;
cin>>n;
int a[n+1] ,mn = 0 , mx = 0 , sum = 0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum += a[i];
mx = max(mx , sum);
mn = min(mn , sum - mx);
}
cout<<sum - mn<<endl;
}
}