# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
162884 | abacaba | Bigger segments (IZhO19_segments) | C++14 | 2 ms | 376 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 <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define int long long
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 5e5 + 15;
int n, m, a[N], p[N], maxp[N], dp[N];
main() {
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = p[i-1] + a[i];
maxp[i] = max(maxp[i-1], p[i]);
}
for(int i = 1; i <= n; ++i) {
int l = 1, r = i - 1;
dp[i] = 1;
while(l <= r) {
int mid = l + r >> 1;
if(2 * p[mid] - maxp[mid - 1] <= p[i])
dp[i] = max(dp[i], dp[mid] + 1), l = mid + 1;
else
r = mid - 1;
}
}
cout << dp[n] << endl;
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... |