Submission #478381

#TimeUsernameProblemLanguageResultExecution timeMemory
478381MilosMilutinovicBigger segments (IZhO19_segments)C++14
0 / 100
1 ms208 KiB
/**
 *    author: m371
 *    created: 07.10.2021 08:30:44
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0, curr = 0;
  int ans = 0;
  for (int i = 0, j = 0; i < n; i++) {
    sum += a[i];
    if (sum >= curr) {
      while (curr + a[j] <= sum - a[j]) {
        curr += a[j];
        sum -= a[j];
        j += 1;
      }
      curr = sum;
      sum = 0;
      ans++; 
      j = i + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
#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...