# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171628 | davitmarg | Bigger segments (IZhO19_segments) | C++17 | 139 ms | 20968 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.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 500005;
int n;
LL a[N],pr[N];
pair<int, LL> dp[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%lld", a + i);
for (int i = 1; i <= n; i++)
{
dp[i] = MP(0, -mod * mod);
pr[i] = pr[i - 1] + a[i];
}
for (int i = 0; i < n; i++)
{
dp[i + 1] = max(dp[i + 1], MP(dp[i].first, dp[i].second - a[i+1]));
int l = i + 1, r = n, m, pos = 0;
while (l <= r)
{
m = (l + r) / 2;
if (pr[m] - pr[i] >= -dp[i].second)
{
r = m - 1;
pos = m;
}
else
l = m + 1;
}
dp[pos] = max(dp[pos], MP(dp[i].first + 1, pr[i] - pr[pos]));
//cout << i << " = " << dp[i].first << " : " << -dp[i].second << endl;
//cout << pos << endl << endl;
}
cout << dp[n].first << 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... |