# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017688 |
2024-07-09T09:29:45 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
74 ms |
8552 KB |
#include <bits/stdc++.h>
using namespace std;
long long dp[300001][2];
int cnt[300001][2];
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 = 5e10, ans;
while (r > l) {
long long lambda = (l+r)/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+1;
else r = lambda-1;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
8284 KB |
Output is correct |
2 |
Correct |
38 ms |
8540 KB |
Output is correct |
3 |
Correct |
39 ms |
8536 KB |
Output is correct |
4 |
Correct |
36 ms |
8536 KB |
Output is correct |
5 |
Correct |
34 ms |
8540 KB |
Output is correct |
6 |
Correct |
40 ms |
8272 KB |
Output is correct |
7 |
Correct |
59 ms |
8276 KB |
Output is correct |
8 |
Correct |
35 ms |
8540 KB |
Output is correct |
9 |
Correct |
60 ms |
8284 KB |
Output is correct |
10 |
Correct |
35 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
8284 KB |
Output is correct |
2 |
Correct |
18 ms |
8540 KB |
Output is correct |
3 |
Correct |
17 ms |
8280 KB |
Output is correct |
4 |
Correct |
28 ms |
8540 KB |
Output is correct |
5 |
Correct |
19 ms |
8284 KB |
Output is correct |
6 |
Correct |
21 ms |
8284 KB |
Output is correct |
7 |
Correct |
33 ms |
8552 KB |
Output is correct |
8 |
Correct |
20 ms |
8540 KB |
Output is correct |
9 |
Correct |
20 ms |
8244 KB |
Output is correct |
10 |
Correct |
28 ms |
8536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8540 KB |
Output is correct |
2 |
Correct |
35 ms |
8520 KB |
Output is correct |
3 |
Correct |
22 ms |
8524 KB |
Output is correct |
4 |
Correct |
26 ms |
8540 KB |
Output is correct |
5 |
Correct |
23 ms |
8528 KB |
Output is correct |
6 |
Correct |
26 ms |
8532 KB |
Output is correct |
7 |
Correct |
34 ms |
8532 KB |
Output is correct |
8 |
Correct |
26 ms |
8540 KB |
Output is correct |
9 |
Correct |
32 ms |
8540 KB |
Output is correct |
10 |
Correct |
27 ms |
8476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
8284 KB |
Output is correct |
2 |
Correct |
38 ms |
8540 KB |
Output is correct |
3 |
Correct |
39 ms |
8536 KB |
Output is correct |
4 |
Correct |
36 ms |
8536 KB |
Output is correct |
5 |
Correct |
34 ms |
8540 KB |
Output is correct |
6 |
Correct |
40 ms |
8272 KB |
Output is correct |
7 |
Correct |
59 ms |
8276 KB |
Output is correct |
8 |
Correct |
35 ms |
8540 KB |
Output is correct |
9 |
Correct |
60 ms |
8284 KB |
Output is correct |
10 |
Correct |
35 ms |
8540 KB |
Output is correct |
11 |
Correct |
20 ms |
8284 KB |
Output is correct |
12 |
Correct |
18 ms |
8540 KB |
Output is correct |
13 |
Correct |
17 ms |
8280 KB |
Output is correct |
14 |
Correct |
28 ms |
8540 KB |
Output is correct |
15 |
Correct |
19 ms |
8284 KB |
Output is correct |
16 |
Correct |
21 ms |
8284 KB |
Output is correct |
17 |
Correct |
33 ms |
8552 KB |
Output is correct |
18 |
Correct |
20 ms |
8540 KB |
Output is correct |
19 |
Correct |
20 ms |
8244 KB |
Output is correct |
20 |
Correct |
28 ms |
8536 KB |
Output is correct |
21 |
Correct |
23 ms |
8540 KB |
Output is correct |
22 |
Correct |
35 ms |
8520 KB |
Output is correct |
23 |
Correct |
22 ms |
8524 KB |
Output is correct |
24 |
Correct |
26 ms |
8540 KB |
Output is correct |
25 |
Correct |
23 ms |
8528 KB |
Output is correct |
26 |
Correct |
26 ms |
8532 KB |
Output is correct |
27 |
Correct |
34 ms |
8532 KB |
Output is correct |
28 |
Correct |
26 ms |
8540 KB |
Output is correct |
29 |
Correct |
32 ms |
8540 KB |
Output is correct |
30 |
Correct |
27 ms |
8476 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
0 ms |
2396 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2392 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
1 ms |
2648 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
1 ms |
2396 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
1 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
60 ms |
8272 KB |
Output is correct |
62 |
Correct |
74 ms |
8536 KB |
Output is correct |
63 |
Correct |
42 ms |
8244 KB |
Output is correct |
64 |
Correct |
74 ms |
8532 KB |
Output is correct |
65 |
Correct |
62 ms |
8536 KB |
Output is correct |
66 |
Correct |
59 ms |
8528 KB |
Output is correct |
67 |
Correct |
62 ms |
8276 KB |
Output is correct |
68 |
Correct |
32 ms |
8528 KB |
Output is correct |
69 |
Correct |
33 ms |
8284 KB |
Output is correct |
70 |
Correct |
24 ms |
8236 KB |
Output is correct |