Submission #1192890

#TimeUsernameProblemLanguageResultExecution timeMemory
1192890lopkusBigger segments (IZhO19_segments)C++20
13 / 100
0 ms328 KiB
#include <bits/stdc++.h>

#define int64_t int

int64_t inf = 1e16;

void solve() {
  int n;
  std::cin >> n;
  std::vector<int64_t> a(n + 1);
  for(int i = 1; i <= n; i++) {
    std::cin >> a[i];
  }
  std::vector<int64_t> pref(n + 1);
  for(int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + a[i];
  }
  std::vector<std::pair<int,int>> dp(n + 1, {0, 0});
  dp[1] = {1, a[1]};
  for(int i = 2; i <= n; i++) {
    for(int j = i - 1; j >= 0; j--) {
      if(pref[i] >= pref[j] + dp[j].second) {
        if(dp[i].first < dp[j].first + 1) {
          dp[i].first = dp[j].first + 1;
          dp[i].second = pref[i] - pref[j];
        }
        else if(dp[i].first == dp[j].first + 1) {
          dp[i].second = std::min(dp[i].second, pref[i] - pref[j]);
        }
      }
    }
  }
  std::cout << dp[n].first;
}


signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int t = 1;
  //std::cin >> t;
  while (t--) {
      solve();
  }

  return 0;
}

Compilation message (stderr)

segments.cpp:5:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+16' to '2147483647' [-Woverflow]
    5 | int64_t inf = 1e16;
      |               ^~~~
#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...