이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Example program
#include <iostream>
#include <string>
using namespace std;
const int N = 5e5 + 5;
typedef long long ll;
int n, ans, a[N];
pair < ll, int > dp[N];
ll pref[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
dp[i] = {pref[i], 1};
}
for (int i = 2; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
if (pref[i] - pref[j] >= dp[j].first) {
if (dp[j].second + 1 > dp[i].second)
dp[i] = {pref[i] - pref[j], dp[j].second + 1};
else if (dp[j].second + 1 == dp[i].second && pref[i] - pref[j] < dp[i].first) {
dp[i].first = pref[i] - pref[j];
}
}
}
}
cout << dp[n].second;
}
| # | 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... |