# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
632599 |
2022-08-20T11:51:01 Z |
phungha |
Feast (NOI19_feast) |
C++14 |
|
1000 ms |
11468 KB |
#include <bits/stdc++.h>
using namespace std;
int n, k, cnt[300001];
long long a[300001], s[300001], dp[300001];
int calc(int lambda) {
// dp[i]: tổng lớn nhất của các đoạn với i phần tử đầu tiên, nếu mỗi đoạn khác rỗng được cộng thêm lambda
// cnt[i]: số đoạn tối thiểu
dp[0] = cnt[0] = 0;
long long dp_max = 0;
int cnt_max = 0;
for (int i = 1; i <= n; i++) {
// không dùng thêm đoạn
dp[i] = dp[i - 1];
cnt[i] = cnt[i - 1];
// sử dụng thêm đoạn
if ((dp_max + s[i] + lambda > dp[i]) || (dp_max + s[i] + lambda == dp[i] && cnt[i] > cnt_max + 1)) {
dp[i] = dp_max + s[i] + lambda;
cnt[i] = cnt_max + 1;
}
if (dp[i] - s[i] > dp_max) {
dp_max = dp[i] - s[i];
cnt_max = cnt[i];
}
}
return cnt[n];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("test70.in", "r", stdin);
//freopen("test01.out", "w", stdout);
cin >> n >> k;
s[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
long long l = 0, r = 1e18;
while (l < r) {
int c = (l + r) / 2;
if (calc(c) >= k)
l = c;
else
r = c - 1;
}
calc(l);
cout << dp[n] - l * cnt[n] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
11052 KB |
Output is correct |
2 |
Correct |
33 ms |
11224 KB |
Output is correct |
3 |
Correct |
31 ms |
11404 KB |
Output is correct |
4 |
Correct |
34 ms |
11308 KB |
Output is correct |
5 |
Correct |
42 ms |
11252 KB |
Output is correct |
6 |
Correct |
34 ms |
11072 KB |
Output is correct |
7 |
Correct |
33 ms |
10972 KB |
Output is correct |
8 |
Correct |
33 ms |
11188 KB |
Output is correct |
9 |
Correct |
31 ms |
11096 KB |
Output is correct |
10 |
Correct |
31 ms |
11216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
9384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
11468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
11052 KB |
Output is correct |
2 |
Correct |
33 ms |
11224 KB |
Output is correct |
3 |
Correct |
31 ms |
11404 KB |
Output is correct |
4 |
Correct |
34 ms |
11308 KB |
Output is correct |
5 |
Correct |
42 ms |
11252 KB |
Output is correct |
6 |
Correct |
34 ms |
11072 KB |
Output is correct |
7 |
Correct |
33 ms |
10972 KB |
Output is correct |
8 |
Correct |
33 ms |
11188 KB |
Output is correct |
9 |
Correct |
31 ms |
11096 KB |
Output is correct |
10 |
Correct |
31 ms |
11216 KB |
Output is correct |
11 |
Incorrect |
26 ms |
9384 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |