# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501798 | dxz05 | Bigger segments (IZhO19_segments) | C++14 | 15 ms | 3220 KiB |
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;
typedef long long ll;
#define MP make_pair
pair<int, ll> dp[3001];
void chmax(pair<int, ll> &x, pair<int, ll> y){
if (x.first < y.first || x.first == y.first && x.second > y.second) x = y;
}
int a[500005];
ll pref[500005];
ll sum(int l, int r){
return pref[r] - pref[l - 1];
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
dp[0] = MP(0, 0ll);
for (int i = 1; i <= n; i++){
for (int j = 0; j < i; j++){
if (sum(j + 1, i) >= dp[j].second) chmax(dp[i], MP(dp[j].first + 1, sum(j + 1, i)));
}
// cout << dp[i].first << ' ' << dp[i].second << endl;
}
cout << dp[n].first;
return 0;
}
Compilation message (stderr)
# | 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... |