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;
#define int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
for (auto x: a) cout << x << " ";
cout << endl;
}
void solve(){
int n; cin >> n;
vector<int> a(n);
FOR(i,0,n) cin >> a[i];
vector<pair<int, int>> dp(n); // dp[i] denotes the maximum number of segments possible and the minimum value of previous segment
dp[0] = {1, a[0]};
FOR(i,1,n){
dp[i] = {dp[i-1].first, dp[i-1].second+a[i]};
int o = a[i];
for (int j = i-1; j >= 0; j--){
if (o >= dp[j].second){
if (dp[j].first+1 > dp[i].first){
dp[i].first = dp[j].first+1;
dp[i].second = o;
}else if (dp[j].first+1 == dp[i].first){
dp[i].second = min(dp[i].second, o);
}
}
o += a[j];
}
}
cout << dp[n-1].first << endl;
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
int t = 1; // cin >> t;
while (t--) solve();
}
# | 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... |