이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef double ldouble;
typedef long long llong;
typedef unsigned int uint;
template<typename T1, typename T2>
ostream& operator<<(ostream& str, const pair<T1, T2>& p)
{
return str << "{" << p.first << ", " << p.second << "}";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int& x: a)
cin >> x;
vector<llong> pref(n);
for (int i = 0; i < n; ++i)
pref[i] = a[i] + (i ? pref[i - 1] : 0);
vector<pair<int, llong>> dp(n);
for (int i = 0; i < n; ++i)
dp[i] = {1, pref[i]};
for (int i = 0; i < n; ++i)
{
int j = -1;
int l = i + 1, r = n - 1;
while (l <= r)
{
int m = (l + r) / 2;
if (pref[m] - pref[i] >= dp[i].second)
{
j = m;
r = m - 1;
}
else
l = m + 1;
}
if (j != -1)
{
dp[j] = max(pair<int, llong>{dp[j].first, -dp[j].second}, {dp[i].first + 1, -(pref[j] - pref[i])});
dp[j].second *= -1;
// cerr << "i: " << i << "; " << "j: " << j << "\t" << dp[j] << endl;
}
}
/*for (int i = 0; i < dp.size(); ++i)
cerr << "dp[" << i << "] = " << dp[i] << endl;*/
cout << max_element(dp.begin(), dp.end())->first << endl;
}
# | 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... |