# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017526 |
2024-07-09T08:39:45 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
48 ms |
11588 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 |
36 ms |
11092 KB |
Output is correct |
2 |
Correct |
48 ms |
11312 KB |
Output is correct |
3 |
Correct |
28 ms |
11352 KB |
Output is correct |
4 |
Correct |
44 ms |
11428 KB |
Output is correct |
5 |
Correct |
28 ms |
11344 KB |
Output is correct |
6 |
Correct |
29 ms |
11088 KB |
Output is correct |
7 |
Correct |
46 ms |
11088 KB |
Output is correct |
8 |
Correct |
30 ms |
11348 KB |
Output is correct |
9 |
Correct |
28 ms |
11092 KB |
Output is correct |
10 |
Correct |
29 ms |
11328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
9388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
11588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
11092 KB |
Output is correct |
2 |
Correct |
48 ms |
11312 KB |
Output is correct |
3 |
Correct |
28 ms |
11352 KB |
Output is correct |
4 |
Correct |
44 ms |
11428 KB |
Output is correct |
5 |
Correct |
28 ms |
11344 KB |
Output is correct |
6 |
Correct |
29 ms |
11088 KB |
Output is correct |
7 |
Correct |
46 ms |
11088 KB |
Output is correct |
8 |
Correct |
30 ms |
11348 KB |
Output is correct |
9 |
Correct |
28 ms |
11092 KB |
Output is correct |
10 |
Correct |
29 ms |
11328 KB |
Output is correct |
11 |
Incorrect |
18 ms |
9388 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |