This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const ll mod = 1e9 + 7, inf = 1e12;
void solve() {
int n; cin >> n;
vector<ll> v(n), pref(n + 1);
for (int i = 0; i < n; ++i) {
cin >> v[i];
pref[i + 1] = pref[i] + v[i];
}
vector<vector<pair<ll, ll>>> dp(n + 1, vector<pair<ll, ll>>(n + 1, {0, 0}));
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
dp[l][r] = max(dp[l][r], { dp[l][r - 1].first, -(-dp[l][r - 1].second + v[r - 1]) });
if (r == l) dp[l][r] = { 1, -v[r - 1] };
//cout << dp[1][1].first << "\n";
ll cnt = dp[l][r].first, sm = -dp[l][r].second;
ll req = pref[r] + sm;
//if(sm < 0) cout << l << " " << r << "\n";
int id = lower_bound(pref.begin(), pref.end(), req) - pref.begin();
if (id > n) continue;
if (sm >= 0 && pref[id] < sm) cout << "E AP JAN STE KLYUCHNIK CHKA ES CHEM JOGE?\n";
if(id >= r) dp[l][id] = max(dp[l][id], { cnt + 1, -(pref[id] - sm) });
}
}
/*for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cout << dp[i][j].first << " ";
}
cout << "\n";
}*/
cout << dp[1][n].first << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//int t; 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... |