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>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
const int N=5e5+11;
const int M=1e6+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const double EPS=1e-9;
int a[N];
ll p[N];
int dp[N];
ll val[N];
struct node{
int val;
};
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
p[i]=p[i-1]+a[i];
}
dp[0]=0;
val[0]=0;
set<pair<ll,int>>S;
S.insert(mp(0,0));
for(int i=1;i<=n;i++){
int j=0;
while(!S.empty()){
pair<ll,int>q=*S.begin();
if(q.x>p[i])break;
S.erase(q);
j=max(j,q.y);
}
dp[i]=dp[j]+1;
val[i]=p[i]-p[j];
S.insert(mp(val[j]+p[j],j));
S.insert(mp(val[i]+p[i],i));
}
cout<<dp[n];
}
# | 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... |