Submission #344521

#TimeUsernameProblemLanguageResultExecution timeMemory
344521NurlykhanBigger segments (IZhO19_segments)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)5e5 + 10; const int mod = (int)1e9 + 7; int n; int a[N]; ll pref[N]; ll get_sum(int l, int r) { return pref[r] - pref[l - 1]; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pref[i] = pref[i - 1] + a[i]; } int ans = 0; for (int i = 1; i <= n; i++) { ll cur_sum = 0; ll prev_sum = get_sum(1, i); int cnt = 0, j = i + 1; while (j <= n) { cur_sum += a[j]; if (cur_sum >= prev_sum) { cur_sum = 0; cnt++; } j++; } ans = max(ans, cnt + 1); } printf("%d", ans); return 0; }

Compilation message (stderr)

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