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;
const int N = 5e5 + 5;
int n, v[N];
struct ura{
int seg, prv;
} dp[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> v[i];
v[i] += v[i - 1];
}
dp[1] = {1, 0};
for (int i = 1; i <= n; i++)
{
if (dp[i].seg < dp[i - 1].seg || (dp[i].seg == dp[i - 1].seg && dp[i].prv < dp[i - 1].prv))
dp[i] = dp[i - 1];
///i e capatul intervalului vechi!
int st = 1, dr = n, j = n + 1;
while (st <= dr)
{
int mid = (st + dr) / 2;
if (2 * v[i] - v[dp[i].prv] <= v[mid])
{
j = mid;
dr = mid - 1;
}
else
st = mid + 1;
}
ura x = {dp[i].seg + 1, i};
if (dp[j].seg < x.seg || (dp[j].seg == x.seg && dp[j].prv < x.prv))
dp[j] = x;
}
cout << dp[n].seg;
return 0;
}
# | 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... |