Submission #376281

#TimeUsernameProblemLanguageResultExecution timeMemory
376281HalogenBigger segments (IZhO19_segments)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int N, presum[500005];

int check(int x) {
    int ans = 1, curseg = presum[x];
    while (x < N) {
        int nx = lower_bound(presum + 1, presum + N + 1, curseg + presum[x]) - presum;
        if (presum[nx] - presum[x] - curseg < 0) return 0;
        curseg = presum[nx] - presum[x];
        ans++;
        x = nx;
        // printf("%lld\n", x);
    }
    return ans;
}

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

    int ans = 0;
    for (int x = 1; x <= N; x++) {
        ans = max(ans, check(x));
    }

    printf("%lld\n", ans);
}

Compilation message (stderr)

segments.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main() {
      |      ^
segments.cpp: In function 'int main()':
segments.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     scanf("%lld", &N);
      |     ~~~~~^~~~~~~~~~~~
segments.cpp:24:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     for (int i = 1; i <= N; i++) scanf("%lld", &presum[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...