Submission #376292

#TimeUsernameProblemLanguageResultExecution timeMemory
376292HalogenBigger segments (IZhO19_segments)C++14
13 / 100
1571 ms548 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int N, lst[500005];

int dp(int x, int sum, int seg) {
    int ans = 0;
    if (x >= N) {
        if (sum >= 0) ans = 0;
        else ans = -10234567898765432;
    }
    else if (sum < 0) ans = dp(x + 1, sum + lst[x], seg + lst[x]);
    else ans = max(
        dp(x + 1, sum + lst[x], seg + lst[x]),
        1 + dp(x + 1, -seg + lst[x], lst[x])
    );

    // printf("%lld %lld %lld\n", ans, x, seg);
    return ans; 
}

main() {
    scanf("%lld", &N);
    for (int i = 0; i < N; i++) scanf("%lld", &lst[i]);
    // for (int i = 2; i <= N; i++) lst[i] += lst[i - 1];

    printf("%lld\n", dp(0, 0, 0));
}

Compilation message (stderr)

segments.cpp:25:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main() {
      |      ^
segments.cpp: In function 'int main()':
segments.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%lld", &N);
      |     ~~~~~^~~~~~~~~~~~
segments.cpp:27:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     for (int i = 0; i < N; i++) scanf("%lld", &lst[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...