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;
typedef long long ll;
typedef vector<ll> vl;
vector<map<ll,ll> > go;
vl w,pr;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
go.assign(n+1,map<ll,ll>());
pr.push_back(0);
for(int i=0;i<n;i++) {
ll t;
cin >> t;
w.push_back(t);
pr.push_back(pr.back()+w.back());
}
go[1][1] = pr[1];
for(int i=1;i<=n;i++) {
while(go[i].size() > 1) {
go[i].erase(go[i].begin());
}
ll num = go[i].begin()->first;
ll ko = go[i].begin()->second;
int nx = lower_bound(pr.begin(),pr.end(),pr[i]+ko)-pr.begin();
if(nx <= n) {
if(go[nx].count(num+1)) {
go[nx][num+1] = min(go[nx][num+1],pr[nx]-pr[i]);
} else {
go[nx][num+1] = pr[nx]-pr[i];
}
}
if(i+1 <= n) {
if(go[i+1].count(num)) {
go[i+1][num] = min(go[i+1][num],ko+pr[i+1]-pr[i]);
} else {
go[i+1][num] = ko+pr[i+1]-pr[i];
}
}
}
cout << go[n].begin()->first << '\n';
}
# | 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... |