#include <iostream>
#include <algorithm>
#include <cmath>
#define ff first
#define ss second
typedef long long ll;
using namespace std;
const int N = 5e5 + 10;
ll pref[N];
pair <ll, ll> dp[N];
ll dpp[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> pref[i];
pref[i] += pref[i - 1];
}
dp[0] = { 0, 0 };
dpp[0] = 0;
for (int i = 1; i <= n; i++) {
int ind = upper_bound(dpp, dpp + i + 1, pref[i]) - dpp - 1;
dp[i] = { dp[ind].first + 1, pref[i] - pref[ind] };
dpp[i] = dp[i].ss + pref[i];
}
cout << dp[n].first << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |