# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
308795 | nikatamliani | Bigger segments (IZhO19_segments) | C++14 | 1 ms | 384 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>
#define f first
#define s second
#define ll long long
using namespace std;
const int N = 5e5 + 10;
pair < int, ll > dp[N];
ll sum[N], n;
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) cin >> sum[i], sum[i] += sum[i - 1];
for(int i = 1; i <= n; ++i) {
int l = 1, r = i, ans = 1;
while(r >= l) {
int m = l + r >> 1;
if(sum[i] - sum[m - 1] >= dp[m - 1].s) {
l = m + 1;
ans = m;
} else {
r = m - 1;
}
}
dp[i].f = dp[ans - 1].f + 1;
dp[i].s = sum[i] - sum[ans - 1];
}
cout << dp[n].f << '\n';
}
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... |