# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991308 |
2024-06-01T21:24:17 Z |
xnqs |
Feast (NOI19_feast) |
C++17 |
|
93 ms |
10996 KB |
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
int x, k;
int arr[300005];
std::pair<int64_t,int> dp[300005][2];
std::pair<int64_t,int> sol(int64_t lambda) {
dp[0][0] = {0,0};
dp[0][1] = {arr[0]-lambda,1};
for (int i = 1; i < x; i++) {
dp[i][0] = std::max(dp[i-1][0],dp[i-1][1]);
dp[i][1] = std::max(std::pair<int64_t,int>(dp[i-1][0].first+arr[i]-lambda,dp[i-1][0].second+1),std::pair<int64_t,int>(dp[i-1][1].first+arr[i],dp[i-1][1].second));
}
return std::max(dp[x-1][0],dp[x-1][1]);
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> x >> k;
for (int i = 0; i < x; i++) {
std::cin >> arr[i];
}
const auto bs = [&]() {
int64_t l = 0, r = 1000000000000000000;
int64_t ret = 69420;
while (l<=r) {
int64_t m = (l+r)>>1;
if (sol(m).second>=k) {
ret = m;
l = m+1;
}
else {
r = m-1;
}
}
return ret;
};
int64_t ret = bs();
std::cout << sol(ret).first + ret*k << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
10844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
10844 KB |
Output is correct |
2 |
Correct |
44 ms |
10840 KB |
Output is correct |
3 |
Correct |
51 ms |
10840 KB |
Output is correct |
4 |
Incorrect |
43 ms |
10844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
10992 KB |
Output is correct |
2 |
Correct |
83 ms |
10840 KB |
Output is correct |
3 |
Correct |
75 ms |
10840 KB |
Output is correct |
4 |
Correct |
75 ms |
10952 KB |
Output is correct |
5 |
Correct |
74 ms |
10840 KB |
Output is correct |
6 |
Correct |
76 ms |
10844 KB |
Output is correct |
7 |
Correct |
82 ms |
10832 KB |
Output is correct |
8 |
Correct |
73 ms |
10956 KB |
Output is correct |
9 |
Correct |
76 ms |
10840 KB |
Output is correct |
10 |
Correct |
93 ms |
10996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2452 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2452 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2452 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
10844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |