# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
819158 |
2023-08-10T08:14:51 Z |
cig32 |
Akcija (COCI21_akcija) |
C++17 |
|
489 ms |
524288 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
bool cmp(pair<int, int> x, pair<int, int> y) {
return x.second < y.second;
}
bool cmp2(pair<int, int> x, pair<int, int> y) {
if(x.first == y.first) return x.second < y.second;
return x.first > y.first;
}
void solve(int tc) {
int n, k;
cin >> n >> k;
pair<int, int> p[n+1];
for(int i=1; i<=n; i++) cin >> p[i].first >> p[i].second;
sort(p+1, p+1+n, cmp);
int dp[2][n+1][k+1];
for(int i=1; i<=n; i++) {
for(int j=1; j<=k; j++) {
dp[0][i][j] = 1e18;
}
}
dp[0][0][1] = 0;
for(int i=2; i<=k; i++) dp[0][0][i] = 1e18;
vector<pair<int, int> > sol;
sol.push_back({0, 0});
for(int i=1; i<=n; i++) {
for(int j=0; j<i; j++) {
for(int l=1; l<=k; l++) {
dp[i&1][j][l] = 1e18;
}
}
int opt[k+1];
for(int j=1; j<=k; j++) opt[j] = 1e18;
for(int j=0; j<i; j++) {
int res[k+1];
int p1 = 1, p2 = 1;
for(int l=1; l<=k; l++) {
if(dp[(i-1)&1][j][p1] < opt[p2]) {
res[l] = dp[(i-1)&1][j][p1++];
}
else {
res[l] = opt[p2++];
}
}
for(int l=1; l<=k; l++) {
opt[l] = res[l];
}
}
for(int j=i; j<=n; j++) {
if(p[j].second >= i) {
for(int l=1; l<=k; l++) dp[i&1][j][l] = opt[l] + p[j].first;
}
else {
for(int l=1; l<=k; l++) dp[i&1][j][l] = 1e18;
}
int res[k+1];
int p1 = 1, p2 = 1;
for(int l=1; l<=k; l++) {
if(dp[(i-1)&1][j][p1] < opt[p2]) {
res[l] = dp[(i-1)&1][j][p1++];
}
else {
res[l] = opt[p2++];
}
}
for(int l=1; l<=k; l++) {
opt[l] = res[l];
}
}
for(int j=i; j<=n; j++) {
for(int l=1; l<=k; l++) {
if(dp[i&1][j][l] <= 1e13) sol.push_back({i, dp[i&1][j][l]});
}
}
}
sort(sol.begin(), sol.end(), cmp2);
for(int i=0; i<k; i++) {
cout << sol[i].first << ' ' << sol[i].second << '\n';
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
33364 KB |
Output is correct |
2 |
Correct |
137 ms |
33308 KB |
Output is correct |
3 |
Correct |
118 ms |
33320 KB |
Output is correct |
4 |
Correct |
122 ms |
33388 KB |
Output is correct |
5 |
Correct |
138 ms |
33380 KB |
Output is correct |
6 |
Correct |
22 ms |
468 KB |
Output is correct |
7 |
Correct |
36 ms |
728 KB |
Output is correct |
8 |
Correct |
23 ms |
596 KB |
Output is correct |
9 |
Correct |
25 ms |
1488 KB |
Output is correct |
10 |
Correct |
58 ms |
8764 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
33364 KB |
Output is correct |
2 |
Correct |
137 ms |
33308 KB |
Output is correct |
3 |
Correct |
118 ms |
33320 KB |
Output is correct |
4 |
Correct |
122 ms |
33388 KB |
Output is correct |
5 |
Correct |
138 ms |
33380 KB |
Output is correct |
6 |
Correct |
22 ms |
468 KB |
Output is correct |
7 |
Correct |
36 ms |
728 KB |
Output is correct |
8 |
Correct |
23 ms |
596 KB |
Output is correct |
9 |
Correct |
25 ms |
1488 KB |
Output is correct |
10 |
Correct |
58 ms |
8764 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
175 ms |
33428 KB |
Output is correct |
15 |
Correct |
186 ms |
33376 KB |
Output is correct |
16 |
Correct |
153 ms |
33336 KB |
Output is correct |
17 |
Correct |
160 ms |
33328 KB |
Output is correct |
18 |
Correct |
174 ms |
33404 KB |
Output is correct |
19 |
Correct |
23 ms |
588 KB |
Output is correct |
20 |
Correct |
29 ms |
728 KB |
Output is correct |
21 |
Correct |
23 ms |
596 KB |
Output is correct |
22 |
Correct |
25 ms |
1492 KB |
Output is correct |
23 |
Correct |
55 ms |
8776 KB |
Output is correct |
24 |
Correct |
0 ms |
324 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
66160 KB |
Output is correct |
2 |
Correct |
357 ms |
66196 KB |
Output is correct |
3 |
Correct |
320 ms |
66152 KB |
Output is correct |
4 |
Correct |
315 ms |
66240 KB |
Output is correct |
5 |
Correct |
379 ms |
66204 KB |
Output is correct |
6 |
Correct |
38 ms |
468 KB |
Output is correct |
7 |
Correct |
47 ms |
1112 KB |
Output is correct |
8 |
Correct |
29 ms |
852 KB |
Output is correct |
9 |
Correct |
45 ms |
2628 KB |
Output is correct |
10 |
Correct |
115 ms |
16956 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3024 KB |
Output is correct |
2 |
Correct |
11 ms |
3152 KB |
Output is correct |
3 |
Correct |
8 ms |
3024 KB |
Output is correct |
4 |
Correct |
6 ms |
2004 KB |
Output is correct |
5 |
Correct |
12 ms |
3152 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
1624 KB |
Output is correct |
8 |
Correct |
2 ms |
1108 KB |
Output is correct |
9 |
Correct |
4 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
8 ms |
3024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
8776 KB |
Output is correct |
2 |
Correct |
34 ms |
8776 KB |
Output is correct |
3 |
Correct |
29 ms |
8760 KB |
Output is correct |
4 |
Correct |
28 ms |
8776 KB |
Output is correct |
5 |
Correct |
37 ms |
8760 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
1092 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
6 ms |
1100 KB |
Output is correct |
10 |
Correct |
9 ms |
2620 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
33364 KB |
Output is correct |
2 |
Correct |
137 ms |
33308 KB |
Output is correct |
3 |
Correct |
118 ms |
33320 KB |
Output is correct |
4 |
Correct |
122 ms |
33388 KB |
Output is correct |
5 |
Correct |
138 ms |
33380 KB |
Output is correct |
6 |
Correct |
22 ms |
468 KB |
Output is correct |
7 |
Correct |
36 ms |
728 KB |
Output is correct |
8 |
Correct |
23 ms |
596 KB |
Output is correct |
9 |
Correct |
25 ms |
1488 KB |
Output is correct |
10 |
Correct |
58 ms |
8764 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
175 ms |
33428 KB |
Output is correct |
15 |
Correct |
186 ms |
33376 KB |
Output is correct |
16 |
Correct |
153 ms |
33336 KB |
Output is correct |
17 |
Correct |
160 ms |
33328 KB |
Output is correct |
18 |
Correct |
174 ms |
33404 KB |
Output is correct |
19 |
Correct |
23 ms |
588 KB |
Output is correct |
20 |
Correct |
29 ms |
728 KB |
Output is correct |
21 |
Correct |
23 ms |
596 KB |
Output is correct |
22 |
Correct |
25 ms |
1492 KB |
Output is correct |
23 |
Correct |
55 ms |
8776 KB |
Output is correct |
24 |
Correct |
0 ms |
324 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
349 ms |
66160 KB |
Output is correct |
28 |
Correct |
357 ms |
66196 KB |
Output is correct |
29 |
Correct |
320 ms |
66152 KB |
Output is correct |
30 |
Correct |
315 ms |
66240 KB |
Output is correct |
31 |
Correct |
379 ms |
66204 KB |
Output is correct |
32 |
Correct |
38 ms |
468 KB |
Output is correct |
33 |
Correct |
47 ms |
1112 KB |
Output is correct |
34 |
Correct |
29 ms |
852 KB |
Output is correct |
35 |
Correct |
45 ms |
2628 KB |
Output is correct |
36 |
Correct |
115 ms |
16956 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
324 KB |
Output is correct |
40 |
Correct |
12 ms |
3024 KB |
Output is correct |
41 |
Correct |
11 ms |
3152 KB |
Output is correct |
42 |
Correct |
8 ms |
3024 KB |
Output is correct |
43 |
Correct |
6 ms |
2004 KB |
Output is correct |
44 |
Correct |
12 ms |
3152 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
4 ms |
1624 KB |
Output is correct |
47 |
Correct |
2 ms |
1108 KB |
Output is correct |
48 |
Correct |
4 ms |
980 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
8 ms |
3024 KB |
Output is correct |
53 |
Correct |
36 ms |
8776 KB |
Output is correct |
54 |
Correct |
34 ms |
8776 KB |
Output is correct |
55 |
Correct |
29 ms |
8760 KB |
Output is correct |
56 |
Correct |
28 ms |
8776 KB |
Output is correct |
57 |
Correct |
37 ms |
8760 KB |
Output is correct |
58 |
Correct |
2 ms |
340 KB |
Output is correct |
59 |
Correct |
5 ms |
1092 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
6 ms |
1100 KB |
Output is correct |
62 |
Correct |
9 ms |
2620 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
7 ms |
2512 KB |
Output is correct |
66 |
Runtime error |
489 ms |
524288 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |