이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |