Submission #344533

#TimeUsernameProblemLanguageResultExecution timeMemory
344533NurlykhanBigger 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 get(int it) { ll sum = 0; for (int i = 0; i <= it; i++) { sum += a[it]; } int cnt = 0; it++; while (it < n) { ll cur_sum = 0; while (it < n && cur_sum < sum) { cur_sum += a[it]; it++; } if (cur_sum >= sum) { cnt++; } sum = cur_sum; } return cnt + 1; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); pref[i] = pref[i - 1] + a[i]; } int ans = 0; ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, get(i)); } printf("%d", ans); return 0; }

Compilation message (stderr)

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