# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299763 | dantoh000 | Bigger segments (IZhO19_segments) | C++14 | 224 ms | 22100 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>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, int> li;
ii dp[500005];
int n;
ll p[500005];
ll k[500005];
priority_queue<li, vector<li>, greater<li> > pq;
int main(){
scanf("%d",&n);
pq.push({0,0});
ii best = {0,0};
for (int i = 1; i <= n; i++){
scanf("%lld",&p[i]);
p[i]+=p[i-1];
/*int j;
for (j = i-1; j >= 0; j--){
if (p[i] >= k[j]) break;
}*/
li last;
while (pq.size() && pq.top().fi <= p[i]){
best = max(best,{dp[pq.top().se].fi,pq.top().se});
last = pq.top(); pq.pop();
}
pq.push(last);
int j = best.se;
dp[i] = {dp[j].fi+1, j};
k[i] = 2*p[i]-p[j];
//printf("%lld: ",2*p[i]-p[j]);
pq.push({k[i],i});
}
printf("%d",dp[n].fi);
}
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... |