제출 #345200

#제출 시각아이디문제언어결과실행 시간메모리
345200tata666Bigger segments (IZhO19_segments)C++17
100 / 100
133 ms10176 KiB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define sz(x) (int)x.size()

using namespace std;

typedef long long llong;

const int MOD = 1e9 + 7;
const int MXN = 5e5 + 7;
const llong INF = 1e18 + 7;

int n, a[MXN], ans[MXN], ind[MXN];
llong pref[MXN];

int main(){
  ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
  }
  ans[1] = 1;
  for(int i = 1; i <= n; i++){
    ind[i] = max(ind[i], ind[i - 1]);
    ans[i] = max(ans[i], ans[i - 1]);
    int j = ind[i];
    int k = upper_bound(pref + 1, pref + n + 1, pref[i] * 2 - pref[j] - 1) - pref;
    ans[k] = max(ans[i] + 1, ans[k]);
    ind[k] = i;
  }
  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...