#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n; cin >> n;
vector<int> a(n + 1), pref(n + 1);
for (int i = 1; i<= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
vector<vector<int>> dp(n + 1, vector<int> (n + 1, 0));
dp[0][0] = 0;
for (int i = 1; i <= n; i++){
dp[i][1] = pref[i];
}
for (int j = 2; j <= n; j++){
for (int i = j; i <= n; i++){
int ini = 1, fin = i;
while(ini < fin){
int m = (ini + fin) / 2;
if (pref[i] < dp[m][j - 1] + pref[m]){
fin = m - 1;
}else{
ini = m;
}
}
ini--;
int suma = pref[i] - pref[ini];
if (suma >= dp[ini][j - 1] && dp[ini][j - 1]) dp[i][j] = suma;
}
}
/*for (int i = 0; i <= n; i++){
for (int j = 0; j <= n; j++){
cout << dp[i][j] << ' ';
}
cout << endl;
}*/
int ans = 1;
for (int i = 1; i <= n; i++){
if (dp[n][i]) ans = max(ans, i);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1572 ms |
336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1572 ms |
336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1572 ms |
336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1572 ms |
336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1572 ms |
336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |