#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;
}
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[n+1][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;
for(int i=1; i<=n; i++) {
for(int j=0; j<i; j++) {
for(int l=1; l<=k; l++) {
dp[i][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][j][p1] < opt[p2]) {
res[l] = dp[i-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][j][l] = opt[l] + p[j].first;
}
else {
for(int l=1; l<=k; l++) dp[i][j][l] = 1e18;
}
int res[k+1];
int p1 = 1, p2 = 1;
for(int l=1; l<=k; l++) {
if(dp[i-1][j][p1] < opt[p2]) {
res[l] = dp[i-1][j][p1++];
}
else {
res[l] = opt[p2++];
}
}
for(int l=1; l<=k; l++) {
opt[l] = res[l];
}
}
}
vector<pair<int, int> > sol;
for(int i=n; i>=0; i--) {
vector<int> v;
for(int j=i; j<=n; j++) {
for(int l=1; l<=k; l++) {
if(dp[i][j][l] <= 1e13) v.push_back(dp[i][j][l]);
}
}
sort(v.begin(), v.end());
for(int x: v) {
sol.push_back({i, x});
}
}
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);
}
// 勿忘初衷
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
90984 KB |
Output is correct |
2 |
Correct |
105 ms |
96036 KB |
Output is correct |
3 |
Correct |
88 ms |
86152 KB |
Output is correct |
4 |
Correct |
88 ms |
84904 KB |
Output is correct |
5 |
Correct |
121 ms |
94764 KB |
Output is correct |
6 |
Correct |
44 ms |
51752 KB |
Output is correct |
7 |
Correct |
54 ms |
62812 KB |
Output is correct |
8 |
Correct |
45 ms |
53836 KB |
Output is correct |
9 |
Correct |
48 ms |
52412 KB |
Output is correct |
10 |
Correct |
58 ms |
63652 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
90984 KB |
Output is correct |
2 |
Correct |
105 ms |
96036 KB |
Output is correct |
3 |
Correct |
88 ms |
86152 KB |
Output is correct |
4 |
Correct |
88 ms |
84904 KB |
Output is correct |
5 |
Correct |
121 ms |
94764 KB |
Output is correct |
6 |
Correct |
44 ms |
51752 KB |
Output is correct |
7 |
Correct |
54 ms |
62812 KB |
Output is correct |
8 |
Correct |
45 ms |
53836 KB |
Output is correct |
9 |
Correct |
48 ms |
52412 KB |
Output is correct |
10 |
Correct |
58 ms |
63652 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
121 ms |
90992 KB |
Output is correct |
15 |
Correct |
127 ms |
96040 KB |
Output is correct |
16 |
Correct |
122 ms |
86256 KB |
Output is correct |
17 |
Correct |
109 ms |
84876 KB |
Output is correct |
18 |
Correct |
128 ms |
94804 KB |
Output is correct |
19 |
Correct |
44 ms |
51788 KB |
Output is correct |
20 |
Correct |
53 ms |
62780 KB |
Output is correct |
21 |
Correct |
46 ms |
53832 KB |
Output is correct |
22 |
Correct |
49 ms |
52400 KB |
Output is correct |
23 |
Correct |
65 ms |
63664 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
152648 KB |
Output is correct |
2 |
Correct |
240 ms |
160232 KB |
Output is correct |
3 |
Correct |
195 ms |
145504 KB |
Output is correct |
4 |
Correct |
217 ms |
143472 KB |
Output is correct |
5 |
Correct |
239 ms |
158336 KB |
Output is correct |
6 |
Correct |
59 ms |
77456 KB |
Output is correct |
7 |
Correct |
85 ms |
94080 KB |
Output is correct |
8 |
Correct |
74 ms |
80716 KB |
Output is correct |
9 |
Correct |
80 ms |
78860 KB |
Output is correct |
10 |
Correct |
119 ms |
99316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8520 KB |
Output is correct |
2 |
Correct |
10 ms |
9084 KB |
Output is correct |
3 |
Correct |
8 ms |
7872 KB |
Output is correct |
4 |
Correct |
6 ms |
7000 KB |
Output is correct |
5 |
Correct |
11 ms |
9524 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
7916 KB |
Output is correct |
8 |
Correct |
4 ms |
5704 KB |
Output is correct |
9 |
Correct |
4 ms |
5972 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
8 ms |
8300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
15760 KB |
Output is correct |
2 |
Correct |
22 ms |
16244 KB |
Output is correct |
3 |
Correct |
26 ms |
15052 KB |
Output is correct |
4 |
Correct |
27 ms |
14908 KB |
Output is correct |
5 |
Correct |
24 ms |
16536 KB |
Output is correct |
6 |
Correct |
4 ms |
6228 KB |
Output is correct |
7 |
Correct |
7 ms |
9040 KB |
Output is correct |
8 |
Correct |
4 ms |
6816 KB |
Output is correct |
9 |
Correct |
8 ms |
7360 KB |
Output is correct |
10 |
Correct |
8 ms |
8904 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
232 KB |
Output is correct |
13 |
Correct |
7 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
90984 KB |
Output is correct |
2 |
Correct |
105 ms |
96036 KB |
Output is correct |
3 |
Correct |
88 ms |
86152 KB |
Output is correct |
4 |
Correct |
88 ms |
84904 KB |
Output is correct |
5 |
Correct |
121 ms |
94764 KB |
Output is correct |
6 |
Correct |
44 ms |
51752 KB |
Output is correct |
7 |
Correct |
54 ms |
62812 KB |
Output is correct |
8 |
Correct |
45 ms |
53836 KB |
Output is correct |
9 |
Correct |
48 ms |
52412 KB |
Output is correct |
10 |
Correct |
58 ms |
63652 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
121 ms |
90992 KB |
Output is correct |
15 |
Correct |
127 ms |
96040 KB |
Output is correct |
16 |
Correct |
122 ms |
86256 KB |
Output is correct |
17 |
Correct |
109 ms |
84876 KB |
Output is correct |
18 |
Correct |
128 ms |
94804 KB |
Output is correct |
19 |
Correct |
44 ms |
51788 KB |
Output is correct |
20 |
Correct |
53 ms |
62780 KB |
Output is correct |
21 |
Correct |
46 ms |
53832 KB |
Output is correct |
22 |
Correct |
49 ms |
52400 KB |
Output is correct |
23 |
Correct |
65 ms |
63664 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
249 ms |
152648 KB |
Output is correct |
28 |
Correct |
240 ms |
160232 KB |
Output is correct |
29 |
Correct |
195 ms |
145504 KB |
Output is correct |
30 |
Correct |
217 ms |
143472 KB |
Output is correct |
31 |
Correct |
239 ms |
158336 KB |
Output is correct |
32 |
Correct |
59 ms |
77456 KB |
Output is correct |
33 |
Correct |
85 ms |
94080 KB |
Output is correct |
34 |
Correct |
74 ms |
80716 KB |
Output is correct |
35 |
Correct |
80 ms |
78860 KB |
Output is correct |
36 |
Correct |
119 ms |
99316 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
10 ms |
8520 KB |
Output is correct |
41 |
Correct |
10 ms |
9084 KB |
Output is correct |
42 |
Correct |
8 ms |
7872 KB |
Output is correct |
43 |
Correct |
6 ms |
7000 KB |
Output is correct |
44 |
Correct |
11 ms |
9524 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
5 ms |
7916 KB |
Output is correct |
47 |
Correct |
4 ms |
5704 KB |
Output is correct |
48 |
Correct |
4 ms |
5972 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
8 ms |
8300 KB |
Output is correct |
53 |
Correct |
23 ms |
15760 KB |
Output is correct |
54 |
Correct |
22 ms |
16244 KB |
Output is correct |
55 |
Correct |
26 ms |
15052 KB |
Output is correct |
56 |
Correct |
27 ms |
14908 KB |
Output is correct |
57 |
Correct |
24 ms |
16536 KB |
Output is correct |
58 |
Correct |
4 ms |
6228 KB |
Output is correct |
59 |
Correct |
7 ms |
9040 KB |
Output is correct |
60 |
Correct |
4 ms |
6816 KB |
Output is correct |
61 |
Correct |
8 ms |
7360 KB |
Output is correct |
62 |
Correct |
8 ms |
8904 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
232 KB |
Output is correct |
65 |
Correct |
7 ms |
4172 KB |
Output is correct |
66 |
Runtime error |
192 ms |
524288 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |