Submission #376951

#TimeUsernameProblemLanguageResultExecution timeMemory
376951joelauBigger segments (IZhO19_segments)C++14
37 / 100
1590 ms2012 KiB
#include <bits/stdc++.h>
using namespace std;

int N,ans[500000];
long long A[500001], sz[500000];

int main() {
    scanf("%d", &N);
    A[0] = 0;
    for (int i = 1; i <= N; ++i) {
        scanf("%lld", &A[i]);
        A[i] += A[i-1];
    }
    for (int i = 0; i < N; ++i) {
        ans[i] = 1, sz[i] = A[i+1];
        for (int j = i-1; j >= 0; --j) if (sz[j] <= A[i+1] - A[j+1]) {
            ans[i] = ans[j]+1, sz[i] = A[i+1] - A[j+1];
            break;
        }
    }
    printf("%d", ans[N-1]);

    return 0;
}

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
segments.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |         scanf("%lld", &A[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...