이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,i,a[100005],opt;
long long pre[100005];
pair<int,long long> dp[100005];
priority_queue<pair<long long,int>> q;
cin>>n;
for (i=1;i<n+1;i++) cin>>a[i];
pre[1]=a[1];
for (i=2;i<n+1;i++) pre[i]=pre[i-1]+a[i];
q.push({-1e18,0});
dp[1]={1,-a[1]};
q.push({-a[1]-pre[1], 1});
opt=0;
for (i=2;i<n+1;i++)
{
dp[i]={1,-pre[i]};
while (abs(q.top().fi)<=pre[i])
{
opt=max(q.top().se, opt);
q.pop();
}
if (opt!=0) dp[i]=max(dp[i], {dp[opt].fi+1, -pre[i]+pre[opt]});
q.push({dp[i].se-pre[i], i});
}
// for (i=1;i<n+1;i++) cout<<dp[i].fi<<" "<<dp[i].se<<"\n";
cout<<dp[n].fi;
}
# | 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... |