# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169367 | SamAnd | Bigger segments (IZhO19_segments) | C++17 | 147 ms | 18912 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 m_p make_pair
const int N = 500005;
int n;
int a[N];
long long p[N];
pair<int, long long> dp[N];
pair<int, long long> mer(const pair<int, long long>& l, const pair<int, long long>& r)
{
if (l.first > r.first)
return l;
if (l.first < r.first)
return r;
if (l.second < r.second)
return l;
return r;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i)
p[i] = p[i - 1] + a[i];
for (int i = 0; i < n; ++i)
{
dp[i + 1] = mer(dp[i + 1], m_p(dp[i].first, dp[i].second + a[i + 1]));
int l = i + 1, r = n;
int ans = -1;
while (l <= r)
{
int m = (l + r) / 2;
if (p[m] - p[i] >= dp[i].second)
{
ans = m;
r = m - 1;
}
else
l = m + 1;
}
if (ans != -1)
dp[ans] = mer(dp[ans], m_p(dp[i].first + 1, p[ans] - p[i]));
}
printf("%d\n", 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... |