#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
int main() {
speed;
int n;
cin>>n;
vector<ll> pre(n+1);
for (int i=1;i<=n;i++) {
cin>>pre[i];
pre[i]+=pre[i-1];
}
vector<pll> dp(n+1);
dp[0]={0,0};
pll now={0,0};
priority_queue<pair<ll,pll>> pq;
for (int i=1;i<=n;i++) {
while (!pq.empty() and -pq.top().F<=pre[i]) {
now=max(now,pq.top().S);
pq.pop();
}
dp[i]={now.F+1,pre[i]-pre[now.S]};
// cout<<dp[i].F<<" "<<dp[i].S<<" dp\n";
pq.push({-(dp[i].S+pre[i]),{dp[i].F,i}});
}
cout<<dp[n].F<<"\n";
return 0;
}
# | 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... |