Submission #344544

#TimeUsernameProblemLanguageResultExecution timeMemory
344544NurlykhanBigger 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[i]; } int cnt = 0; //cout << "(" << 0 << ", "<< it << ") " << sum << "\n"; it++; while (it < n) { ll cur_sum = 0; // cout << "(" << it << ", "; while (it < n && cur_sum < sum) { cur_sum += a[it]; it++; } // cout << it - 1 << ") " << cur_sum << "\n"; 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]; } //8 2 8 7 2 8 2 8 5 2 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:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segments.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         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...