# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017537 |
2024-07-09T08:43:10 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
1000 ms |
8564 KB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n,k; cin >> n >> k;
int a[n+1];
for (int i = 1; i <= n; cin >> a[i++]) {}
long long l = 0, r = 1000, ans;
while (r > l) {
long long lambda = (l+r)/2;
long long dp[n+1][2];
int cnt[n+1][2];
dp[0][0] = 0;
cnt[0][0] = 0;
dp[0][1] = -1e18;
for (int i = 1; i <= n; i++) {
if (dp[i-1][0] > dp[i-1][1]) {
dp[i][0] = dp[i-1][0];
cnt[i][0] = cnt[i-1][0];
} else {
dp[i][0]= dp[i-1][1];
cnt[i][0] = cnt[i-1][1];
}
if (dp[i-1][0] - lambda > dp[i-1][1]) {
dp[i][1] = dp[i-1][0] - lambda + a[i];
cnt[i][1] = cnt[i-1][0] + 1;
} else {
dp[i][1] = dp[i-1][1] + a[i];
cnt[i][1] = cnt[i-1][1];
}
}
double friends;
if (dp[n][0] > dp[n][1]) {
ans = dp[n][0] + lambda*cnt[n][0];
friends = cnt[n][0];
} else {
ans = dp[n][1] + lambda*cnt[n][1];
friends = cnt[n][1];
}
if (friends == k) {
break;
}
if (friends > k) l = lambda;
else r = lambda;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8276 KB |
Output is correct |
2 |
Correct |
29 ms |
8524 KB |
Output is correct |
3 |
Correct |
34 ms |
8528 KB |
Output is correct |
4 |
Correct |
27 ms |
8520 KB |
Output is correct |
5 |
Correct |
27 ms |
8564 KB |
Output is correct |
6 |
Correct |
47 ms |
8276 KB |
Output is correct |
7 |
Correct |
34 ms |
8280 KB |
Output is correct |
8 |
Correct |
27 ms |
8540 KB |
Output is correct |
9 |
Correct |
26 ms |
8272 KB |
Output is correct |
10 |
Correct |
27 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
8284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
8420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8276 KB |
Output is correct |
2 |
Correct |
29 ms |
8524 KB |
Output is correct |
3 |
Correct |
34 ms |
8528 KB |
Output is correct |
4 |
Correct |
27 ms |
8520 KB |
Output is correct |
5 |
Correct |
27 ms |
8564 KB |
Output is correct |
6 |
Correct |
47 ms |
8276 KB |
Output is correct |
7 |
Correct |
34 ms |
8280 KB |
Output is correct |
8 |
Correct |
27 ms |
8540 KB |
Output is correct |
9 |
Correct |
26 ms |
8272 KB |
Output is correct |
10 |
Correct |
27 ms |
8284 KB |
Output is correct |
11 |
Execution timed out |
1077 ms |
8284 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |