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 pb push_back
#define s second
#define f first
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define pii pair<int,int>
#define ll long long
#define int ll //?
using namespace std;
const int N = 5e5 + 5;
int a[N],p[N];
pii dp[N];
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++){
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
dp[0] = {1,0};
for (int i = 1; i <= n; i++){
dp[i] = max(dp[i],dp[i - 1]);
int val = 2*p[i] - dp[i].s;
int l = i + 1,r = n,res = 0;
while (l <= r){
int mid = (l + r) >> 1;
if (p[mid] >= val){
res = mid;
r = mid - 1;
}else{
l = mid + 1;
}
}
if (res) dp[res] = max(dp[res],{dp[i].f + 1,p[i]});
}
cout<<dp[n].f;
}
# | 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... |