# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
543392 |
2022-03-30T13:15:01 Z |
fcw |
Feast (NOI19_feast) |
C++17 |
|
655 ms |
12012 KB |
#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
const lint INF = 3.1e14;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k;
cin>>n>>k;
vector<lint>a(n);
for(int i=0;i<n;i++) cin>>a[i];
double lo = 0, hi = INF;
for(int i=0;i<150;i++){
double mid = (lo + hi) / 2;
vector<array<pair<double, lint>, 2>>dp(n+1);
dp[0][0] = {0, 0}, dp[0][1] = {-INF, 0};
for(int i=0;i<n;i++){
dp[i+1][1] = max(make_pair(dp[i][1].st + a[i], dp[i][1].nd),
make_pair(dp[i][0].st + a[i] - mid, dp[i][0].nd + 1));
dp[i+1][0] = max(dp[i][0], dp[i][1]);
}
if(max(dp[n][0], dp[n][1]).nd >= k) lo = mid;
else hi = mid;
}
double mid = hi;
vector<array<double, 2>>dp(n+1);
dp[0][0] = 0, dp[0][1] = -INF;
for(int i=0;i<n;i++){
dp[i+1][1] = max(dp[i][1] + a[i], dp[i][0] + a[i] - mid);
dp[i+1][0] = max(dp[i][0], dp[i][1]);
}
cout<< lint(round(max(dp[n][0], dp[n][1]) + mid * k))<<"\n";
return 0;
}
/*
[ ]Leu o problema certo???
[ ]Ver se precisa de long long
[ ]Viu o limite dos fors (é n? é m?)
[ ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[ ]Testar sample
[ ]Testar casos de borda
[ ]1LL no 1LL << i
[ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
372 ms |
11692 KB |
Output is correct |
2 |
Correct |
357 ms |
11872 KB |
Output is correct |
3 |
Correct |
359 ms |
11980 KB |
Output is correct |
4 |
Correct |
341 ms |
11912 KB |
Output is correct |
5 |
Correct |
349 ms |
11848 KB |
Output is correct |
6 |
Correct |
320 ms |
11692 KB |
Output is correct |
7 |
Correct |
348 ms |
11816 KB |
Output is correct |
8 |
Correct |
332 ms |
11932 KB |
Output is correct |
9 |
Correct |
341 ms |
11692 KB |
Output is correct |
10 |
Correct |
331 ms |
11764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
11732 KB |
Output is correct |
2 |
Correct |
358 ms |
12012 KB |
Output is correct |
3 |
Correct |
331 ms |
11700 KB |
Output is correct |
4 |
Correct |
349 ms |
11860 KB |
Output is correct |
5 |
Correct |
328 ms |
11716 KB |
Output is correct |
6 |
Correct |
336 ms |
11732 KB |
Output is correct |
7 |
Correct |
341 ms |
11980 KB |
Output is correct |
8 |
Correct |
362 ms |
11936 KB |
Output is correct |
9 |
Correct |
325 ms |
11624 KB |
Output is correct |
10 |
Correct |
367 ms |
11888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
11932 KB |
Output is correct |
2 |
Correct |
451 ms |
11724 KB |
Output is correct |
3 |
Correct |
410 ms |
11852 KB |
Output is correct |
4 |
Correct |
454 ms |
11728 KB |
Output is correct |
5 |
Correct |
416 ms |
11860 KB |
Output is correct |
6 |
Correct |
424 ms |
11900 KB |
Output is correct |
7 |
Correct |
434 ms |
11992 KB |
Output is correct |
8 |
Correct |
439 ms |
11964 KB |
Output is correct |
9 |
Correct |
452 ms |
11968 KB |
Output is correct |
10 |
Correct |
442 ms |
11896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
4 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
368 KB |
Output is correct |
29 |
Correct |
3 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
372 ms |
11692 KB |
Output is correct |
2 |
Correct |
357 ms |
11872 KB |
Output is correct |
3 |
Correct |
359 ms |
11980 KB |
Output is correct |
4 |
Correct |
341 ms |
11912 KB |
Output is correct |
5 |
Correct |
349 ms |
11848 KB |
Output is correct |
6 |
Correct |
320 ms |
11692 KB |
Output is correct |
7 |
Correct |
348 ms |
11816 KB |
Output is correct |
8 |
Correct |
332 ms |
11932 KB |
Output is correct |
9 |
Correct |
341 ms |
11692 KB |
Output is correct |
10 |
Correct |
331 ms |
11764 KB |
Output is correct |
11 |
Correct |
335 ms |
11732 KB |
Output is correct |
12 |
Correct |
358 ms |
12012 KB |
Output is correct |
13 |
Correct |
331 ms |
11700 KB |
Output is correct |
14 |
Correct |
349 ms |
11860 KB |
Output is correct |
15 |
Correct |
328 ms |
11716 KB |
Output is correct |
16 |
Correct |
336 ms |
11732 KB |
Output is correct |
17 |
Correct |
341 ms |
11980 KB |
Output is correct |
18 |
Correct |
362 ms |
11936 KB |
Output is correct |
19 |
Correct |
325 ms |
11624 KB |
Output is correct |
20 |
Correct |
367 ms |
11888 KB |
Output is correct |
21 |
Correct |
416 ms |
11932 KB |
Output is correct |
22 |
Correct |
451 ms |
11724 KB |
Output is correct |
23 |
Correct |
410 ms |
11852 KB |
Output is correct |
24 |
Correct |
454 ms |
11728 KB |
Output is correct |
25 |
Correct |
416 ms |
11860 KB |
Output is correct |
26 |
Correct |
424 ms |
11900 KB |
Output is correct |
27 |
Correct |
434 ms |
11992 KB |
Output is correct |
28 |
Correct |
439 ms |
11964 KB |
Output is correct |
29 |
Correct |
452 ms |
11968 KB |
Output is correct |
30 |
Correct |
442 ms |
11896 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
2 ms |
340 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
3 ms |
340 KB |
Output is correct |
55 |
Correct |
4 ms |
340 KB |
Output is correct |
56 |
Correct |
3 ms |
340 KB |
Output is correct |
57 |
Correct |
3 ms |
340 KB |
Output is correct |
58 |
Correct |
4 ms |
368 KB |
Output is correct |
59 |
Correct |
3 ms |
340 KB |
Output is correct |
60 |
Correct |
3 ms |
340 KB |
Output is correct |
61 |
Incorrect |
655 ms |
11724 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |