Submission #370412

#TimeUsernameProblemLanguageResultExecution timeMemory
370412casperwangBigger segments (IZhO19_segments)C++14
0 / 100
0 ms364 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 500000;
int n;
int a[MAXN+1];
int pre[MAXN+1];
pii dp[MAXN+1];
int L, R;
int ans;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], pre[i] = pre[i-1] + a[i];
  L = 0, R = 0;
  for (int i = 2; i <= n; i++) {
    int l = L, r = R;
    while (l < r) {
      int mid = (l + r + 1) >> 1;
      if (pre[i] - pre[mid] >= dp[mid].ss)
        l = mid;
      else
        r = mid-1;
    }
    dp[i] = pii(dp[l].ff + 1, pre[i] - pre[l]);
    L = l;
    R++;
  }
  cout << dp[n].ff << '\n';
}
#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...