ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1296. Hyperjump

Why WA4?
Posted by Tigra 2 Mar 2016 13:40
#include <bits/stdc++.h>

using namespace std;

const int maxn = 60007;
int a[maxn];
int dp[maxn];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    dp[0] = 0;
    for (int i = 1; i <= n; ++i)
        dp[i] = max(dp[i - 1] + a[i],  max(0,a[i]));

    int ans = *max_element(dp, dp + n);
    cout << ans;
    system("pause");
    return 0;

}
Re: Why WA4?
max(0, a[i]). This is wrong!
You must get sum of consecutive elements.

Edited by author 07.11.2018 20:19