# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
892788 |
2023-12-26T00:43:39 Z |
ayalla |
Feast (NOI19_feast) |
C++14 |
|
176 ms |
12356 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long int
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 300005
#define mod 998244353
int n, k;
int a[MAXN];
pi solve(int lambda)
{
vector<int> dp(n + 1);
vector<int> cnt(n + 1);
dp[0] = 0;
cnt[0] = 0;
pi best = {0, 0};
pi curr = {0, 0};
auto f = [&](pi x)
{
return dp[x.fir] + x.sec;
};
for (int i = 1; i <= n; i++)
{
dp[i] = dp[i - 1];
cnt[i] = cnt[i - 1];
int id = i - 1;
best.sec += a[id];
if (f(best) < f({i - 1, a[id]}))
{
best = {i - 1, a[id]};
}
else if (f(best) == f({i - 1, a[id]}) && cnt[best.fir] > cnt[i - 1])
{
best = {i - 1, a[id]};
}
int s = dp[best.fir] + best.sec - lambda;
if (s > dp[i])
{
dp[i] = s;
cnt[i] = cnt[best.fir] + 1;
}
}
return {dp[n], cnt[n]};
}
int aliens_trick()
{
int l = 0, r = 1e15;
while (l < r)
{
int mid = (l + r) >> 1;
pi ans = solve(mid);
(ans.sec > k) ? l = mid + 1 : r = mid;
}
pi ans = solve(l);
return ans.fir + (l * k);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
cout << aliens_trick() << endl;
return 0;
}
Compilation message
feast.cpp: In function 'std::pair<long long int, long long int> solve(long long int)':
feast.cpp:29:6: warning: variable 'curr' set but not used [-Wunused-but-set-variable]
29 | pi curr = {0, 0};
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
7372 KB |
Output is correct |
2 |
Correct |
107 ms |
7492 KB |
Output is correct |
3 |
Correct |
114 ms |
7568 KB |
Output is correct |
4 |
Correct |
77 ms |
7928 KB |
Output is correct |
5 |
Correct |
93 ms |
7588 KB |
Output is correct |
6 |
Correct |
115 ms |
7376 KB |
Output is correct |
7 |
Correct |
107 ms |
7448 KB |
Output is correct |
8 |
Correct |
119 ms |
7656 KB |
Output is correct |
9 |
Correct |
110 ms |
7548 KB |
Output is correct |
10 |
Correct |
112 ms |
7460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
7428 KB |
Output is correct |
2 |
Correct |
113 ms |
7608 KB |
Output is correct |
3 |
Correct |
106 ms |
7444 KB |
Output is correct |
4 |
Correct |
87 ms |
7516 KB |
Output is correct |
5 |
Correct |
112 ms |
10188 KB |
Output is correct |
6 |
Correct |
116 ms |
8780 KB |
Output is correct |
7 |
Correct |
89 ms |
8760 KB |
Output is correct |
8 |
Correct |
113 ms |
10424 KB |
Output is correct |
9 |
Correct |
102 ms |
10188 KB |
Output is correct |
10 |
Correct |
109 ms |
8696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
9504 KB |
Output is correct |
2 |
Correct |
133 ms |
7396 KB |
Output is correct |
3 |
Correct |
143 ms |
10000 KB |
Output is correct |
4 |
Correct |
139 ms |
7412 KB |
Output is correct |
5 |
Correct |
151 ms |
9544 KB |
Output is correct |
6 |
Correct |
118 ms |
7564 KB |
Output is correct |
7 |
Correct |
100 ms |
7508 KB |
Output is correct |
8 |
Correct |
135 ms |
7480 KB |
Output is correct |
9 |
Correct |
139 ms |
7528 KB |
Output is correct |
10 |
Correct |
137 ms |
7556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
7372 KB |
Output is correct |
2 |
Correct |
107 ms |
7492 KB |
Output is correct |
3 |
Correct |
114 ms |
7568 KB |
Output is correct |
4 |
Correct |
77 ms |
7928 KB |
Output is correct |
5 |
Correct |
93 ms |
7588 KB |
Output is correct |
6 |
Correct |
115 ms |
7376 KB |
Output is correct |
7 |
Correct |
107 ms |
7448 KB |
Output is correct |
8 |
Correct |
119 ms |
7656 KB |
Output is correct |
9 |
Correct |
110 ms |
7548 KB |
Output is correct |
10 |
Correct |
112 ms |
7460 KB |
Output is correct |
11 |
Correct |
121 ms |
7428 KB |
Output is correct |
12 |
Correct |
113 ms |
7608 KB |
Output is correct |
13 |
Correct |
106 ms |
7444 KB |
Output is correct |
14 |
Correct |
87 ms |
7516 KB |
Output is correct |
15 |
Correct |
112 ms |
10188 KB |
Output is correct |
16 |
Correct |
116 ms |
8780 KB |
Output is correct |
17 |
Correct |
89 ms |
8760 KB |
Output is correct |
18 |
Correct |
113 ms |
10424 KB |
Output is correct |
19 |
Correct |
102 ms |
10188 KB |
Output is correct |
20 |
Correct |
109 ms |
8696 KB |
Output is correct |
21 |
Correct |
135 ms |
9504 KB |
Output is correct |
22 |
Correct |
133 ms |
7396 KB |
Output is correct |
23 |
Correct |
143 ms |
10000 KB |
Output is correct |
24 |
Correct |
139 ms |
7412 KB |
Output is correct |
25 |
Correct |
151 ms |
9544 KB |
Output is correct |
26 |
Correct |
118 ms |
7564 KB |
Output is correct |
27 |
Correct |
100 ms |
7508 KB |
Output is correct |
28 |
Correct |
135 ms |
7480 KB |
Output is correct |
29 |
Correct |
139 ms |
7528 KB |
Output is correct |
30 |
Correct |
137 ms |
7556 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
360 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
600 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
492 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
472 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
146 ms |
10396 KB |
Output is correct |
62 |
Correct |
166 ms |
10664 KB |
Output is correct |
63 |
Correct |
146 ms |
12356 KB |
Output is correct |
64 |
Correct |
176 ms |
10548 KB |
Output is correct |
65 |
Correct |
155 ms |
10956 KB |
Output is correct |
66 |
Correct |
129 ms |
10520 KB |
Output is correct |
67 |
Correct |
148 ms |
10436 KB |
Output is correct |
68 |
Correct |
144 ms |
10552 KB |
Output is correct |
69 |
Correct |
93 ms |
10416 KB |
Output is correct |
70 |
Correct |
135 ms |
10312 KB |
Output is correct |