This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector <long long> a(n+1), p(n+1, 0);
for(int i = 1; i <= n; i++){
cin >> a[i];
p[i] = p[i-1] + a[i];
}
vector <vector <long long>> v, v1;
v.resize(n+1);
v1.resize(n+1);
for(int i = 1; i <= n; i++){
long long s = 0;
for(int j = i-1; j >= 1; j--){
s += a[j+1];
int t = upper_bound(v[j].begin(), v[j].end(), s) - v[j].begin();
if(t != 0){
v[i].push_back(s);
v1[i].push_back(v1[j][t-1]+1);
}
}
s += a[1];
v[i].push_back(s);
v1[i].push_back(1);
for(int j = 1; j < (int)v1[i].size(); j++){
v1[i][j] = max(v1[i][j],v1[i][j-1]);
}
}
cout << v1[n].back();
}
# | 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... |