#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e
#define all(a) a.begin(),a.end()
using vp=vec(pii);
signed main(){
_3HspL4A;
int n,k;
cin>>n>>k;
vp a(n);
rep(i,n){
cin>>a[i].se>>a[i].fi;
}
sort(all(a));
vec(vec(vi)) dp(n+1,vec(vi)(n+2,vi()));
dp[0][0]={0};
rep(i,n){
dp[i+1]=dp[i];
auto [d,w]=a[i];
rep(j,d){
if(!sz(dp[i][j])) continue;
for(auto s:dp[i][j]){
dp[i+1][j+1].pb(s+w);
}
}
rep(j,n+1){
sort(all(dp[i+1][j]));
while(sz(dp[i+1][j])>k){
dp[i+1][j].pop_back();
}
}
}
vp pns;
for(int j=n;j>=1;j--){
reverse(all(dp[n][j]));
while(min(k,sz(dp[n][j]))){
pns.pb({j,dp[n][j].back()});
dp[n][j].pop_back();
k-=1;
}
}
while(k){
pns.pb({0,0});
k-=1;
}
for(auto p:pns){
print(p.fi,p.se);
}
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
143984 KB |
Output is correct |
2 |
Correct |
251 ms |
155276 KB |
Output is correct |
3 |
Correct |
213 ms |
130236 KB |
Output is correct |
4 |
Correct |
211 ms |
129128 KB |
Output is correct |
5 |
Correct |
251 ms |
152520 KB |
Output is correct |
6 |
Correct |
82 ms |
77624 KB |
Output is correct |
7 |
Correct |
87 ms |
93880 KB |
Output is correct |
8 |
Correct |
75 ms |
80644 KB |
Output is correct |
9 |
Correct |
73 ms |
78084 KB |
Output is correct |
10 |
Correct |
165 ms |
96252 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 |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
143984 KB |
Output is correct |
2 |
Correct |
251 ms |
155276 KB |
Output is correct |
3 |
Correct |
213 ms |
130236 KB |
Output is correct |
4 |
Correct |
211 ms |
129128 KB |
Output is correct |
5 |
Correct |
251 ms |
152520 KB |
Output is correct |
6 |
Correct |
82 ms |
77624 KB |
Output is correct |
7 |
Correct |
87 ms |
93880 KB |
Output is correct |
8 |
Correct |
75 ms |
80644 KB |
Output is correct |
9 |
Correct |
73 ms |
78084 KB |
Output is correct |
10 |
Correct |
165 ms |
96252 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 |
352 KB |
Output is correct |
14 |
Correct |
244 ms |
143856 KB |
Output is correct |
15 |
Correct |
274 ms |
155292 KB |
Output is correct |
16 |
Correct |
206 ms |
130216 KB |
Output is correct |
17 |
Correct |
206 ms |
129176 KB |
Output is correct |
18 |
Correct |
240 ms |
152592 KB |
Output is correct |
19 |
Correct |
63 ms |
77644 KB |
Output is correct |
20 |
Correct |
82 ms |
94028 KB |
Output is correct |
21 |
Correct |
65 ms |
80640 KB |
Output is correct |
22 |
Correct |
67 ms |
78028 KB |
Output is correct |
23 |
Correct |
104 ms |
96280 KB |
Output is correct |
24 |
Correct |
0 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 |
319 ms |
172364 KB |
Output is correct |
2 |
Correct |
335 ms |
185872 KB |
Output is correct |
3 |
Correct |
285 ms |
155540 KB |
Output is correct |
4 |
Correct |
287 ms |
154816 KB |
Output is correct |
5 |
Correct |
326 ms |
182380 KB |
Output is correct |
6 |
Correct |
63 ms |
77628 KB |
Output is correct |
7 |
Correct |
78 ms |
94104 KB |
Output is correct |
8 |
Correct |
66 ms |
80716 KB |
Output is correct |
9 |
Correct |
67 ms |
78664 KB |
Output is correct |
10 |
Correct |
123 ms |
102992 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2260 KB |
Output is correct |
2 |
Correct |
9 ms |
2388 KB |
Output is correct |
3 |
Correct |
6 ms |
1748 KB |
Output is correct |
4 |
Correct |
5 ms |
1364 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
536 KB |
Output is correct |
9 |
Correct |
1 ms |
460 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 |
324 KB |
Output is correct |
13 |
Correct |
5 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
7332 KB |
Output is correct |
2 |
Correct |
14 ms |
7124 KB |
Output is correct |
3 |
Correct |
13 ms |
5976 KB |
Output is correct |
4 |
Correct |
12 ms |
5984 KB |
Output is correct |
5 |
Correct |
14 ms |
7380 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
1236 KB |
Output is correct |
8 |
Correct |
1 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
1088 KB |
Output is correct |
10 |
Correct |
4 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
5 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
143984 KB |
Output is correct |
2 |
Correct |
251 ms |
155276 KB |
Output is correct |
3 |
Correct |
213 ms |
130236 KB |
Output is correct |
4 |
Correct |
211 ms |
129128 KB |
Output is correct |
5 |
Correct |
251 ms |
152520 KB |
Output is correct |
6 |
Correct |
82 ms |
77624 KB |
Output is correct |
7 |
Correct |
87 ms |
93880 KB |
Output is correct |
8 |
Correct |
75 ms |
80644 KB |
Output is correct |
9 |
Correct |
73 ms |
78084 KB |
Output is correct |
10 |
Correct |
165 ms |
96252 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 |
352 KB |
Output is correct |
14 |
Correct |
244 ms |
143856 KB |
Output is correct |
15 |
Correct |
274 ms |
155292 KB |
Output is correct |
16 |
Correct |
206 ms |
130216 KB |
Output is correct |
17 |
Correct |
206 ms |
129176 KB |
Output is correct |
18 |
Correct |
240 ms |
152592 KB |
Output is correct |
19 |
Correct |
63 ms |
77644 KB |
Output is correct |
20 |
Correct |
82 ms |
94028 KB |
Output is correct |
21 |
Correct |
65 ms |
80640 KB |
Output is correct |
22 |
Correct |
67 ms |
78028 KB |
Output is correct |
23 |
Correct |
104 ms |
96280 KB |
Output is correct |
24 |
Correct |
0 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 |
319 ms |
172364 KB |
Output is correct |
28 |
Correct |
335 ms |
185872 KB |
Output is correct |
29 |
Correct |
285 ms |
155540 KB |
Output is correct |
30 |
Correct |
287 ms |
154816 KB |
Output is correct |
31 |
Correct |
326 ms |
182380 KB |
Output is correct |
32 |
Correct |
63 ms |
77628 KB |
Output is correct |
33 |
Correct |
78 ms |
94104 KB |
Output is correct |
34 |
Correct |
66 ms |
80716 KB |
Output is correct |
35 |
Correct |
67 ms |
78664 KB |
Output is correct |
36 |
Correct |
123 ms |
102992 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
324 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
10 ms |
2260 KB |
Output is correct |
41 |
Correct |
9 ms |
2388 KB |
Output is correct |
42 |
Correct |
6 ms |
1748 KB |
Output is correct |
43 |
Correct |
5 ms |
1364 KB |
Output is correct |
44 |
Correct |
9 ms |
2516 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
3 ms |
852 KB |
Output is correct |
47 |
Correct |
1 ms |
536 KB |
Output is correct |
48 |
Correct |
1 ms |
460 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 |
324 KB |
Output is correct |
52 |
Correct |
5 ms |
1620 KB |
Output is correct |
53 |
Correct |
14 ms |
7332 KB |
Output is correct |
54 |
Correct |
14 ms |
7124 KB |
Output is correct |
55 |
Correct |
13 ms |
5976 KB |
Output is correct |
56 |
Correct |
12 ms |
5984 KB |
Output is correct |
57 |
Correct |
14 ms |
7380 KB |
Output is correct |
58 |
Correct |
1 ms |
596 KB |
Output is correct |
59 |
Correct |
2 ms |
1236 KB |
Output is correct |
60 |
Correct |
1 ms |
832 KB |
Output is correct |
61 |
Correct |
2 ms |
1088 KB |
Output is correct |
62 |
Correct |
4 ms |
2260 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
5 ms |
1620 KB |
Output is correct |
66 |
Runtime error |
1209 ms |
524288 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |