#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |