# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
180307 | rzbt | Bigger segments (IZhO19_segments) | C++14 | 281 ms | 53240 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 mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 500005
typedef long long ll;
using namespace std;
ll n;
ll mz=0;
ll tz=0;
ll niz[MAXN];
pair<ll,ll> dp[MAXN];
ll pref[MAXN];
ll res[MAXN];
set<pair<ll,ll> > s;
int main()
{
scanf("%lld", &n);
for(ll i=1;i<=n;i++){
scanf("%lld",niz+i);
pref[i]=pref[i-1]+niz[i];
}
//dp[i]=mp(pref[i],1);
ll dokle=0;
for(ll i=1;i<=n;i++){
//if(!s.empty())printf(" %d %d\n")
while(!s.empty() && s.begin()->F<=pref[i]){
dokle=max(dokle,s.begin()->S);
s.erase(s.begin());
}
//printf("%lld %lld\n",i,dokle);
dp[i]=mp(pref[i]-pref[dokle],res[dokle]+1);
res[i]=max(res[i-1],dp[i].S);
s.insert(mp(dp[i].F+pref[i],i));
}
printf("%lld",res[n]);
return 0;
}
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... |