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>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
fast;
}
int main()
{
setIO();
int n;
cin>>n;
vl a(n + 1),p(n + 1);
vpll dp(n + 1);//dp[i] stores {maxSegmentLength, -minSumOfLastSegment}
for (int i = 1;i<=n;i++){cin>>a[i];p[i] = p[i - 1] + a[i];}
int ans = 1;
for (int i = 1;i<=n;i++){
dp[i] = {1,-p[1]};
for (int j = i - 1;j>=1;j--){
ll currentLast = p[i] - p[j];
if (currentLast >= -dp[j].second)
dp[i] = max(dp[i],{dp[j].first + 1,-currentLast});
}
//cout<<dp[i].first<<" "<<dp[i].second<<endl;
ans = max(ans,(int)dp[i].first);
}
cout<<ans;
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... |