# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201389 | guangxuan | Bigger segments (IZhO19_segments) | C++14 | 162 ms | 15324 KiB |
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 a[500009];
long long rs[500009];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
rs[i+1]=rs[i]+a[i];
}
pair<int,int> res = {0,0};
pair<int,long long> dp;
priority_queue<pair<long long,pair<int,int> >,vector<pair<long long,pair<int,int> > >, greater< pair<long long,pair<int,int> > > > updates;
for(int i=1;i<=n;i++){
while(updates.size() && updates.top().first<=rs[i]){
pair<int,int> cur = updates.top().second;
updates.pop();
res = max(res,cur);
}
dp = {res.first,rs[res.second] - rs[i]};
dp.first++;
updates.push({rs[i]-dp.second,{dp.first,i}});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp.first);
}
Compilation message (stderr)
# | 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... |