# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486854 | SirCovidThe19th | Bigger segments (IZhO19_segments) | C++17 | 273 ms | 44216 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;
#define ll long long
#define f first
#define s second
const int mx = 5e5 + 5;
int n; ll pre[mx]; vector<int> ok[mx]; pair<int, ll> bst, dp[mx];
int main(){
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> pre[i], pre[i] += pre[i - 1];
ok[1].push_back(0);
for (int i = 1, l = 0; i <= n; i++){
for (int X : ok[i]) bst = max(bst, {dp[X].f + 1, X});
dp[i] = {bst.f, pre[i] - pre[bst.s]};
int okPos = lower_bound(pre + 1, pre + n + 1, pre[i] + dp[i].s) - pre;
ok[okPos].push_back(i);
}
cout<<dp[n].f<<endl;
}
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... |