#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+2,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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
144012 KB |
Output is correct |
2 |
Correct |
240 ms |
155352 KB |
Output is correct |
3 |
Correct |
197 ms |
130252 KB |
Output is correct |
4 |
Correct |
198 ms |
129020 KB |
Output is correct |
5 |
Correct |
241 ms |
152600 KB |
Output is correct |
6 |
Correct |
62 ms |
77580 KB |
Output is correct |
7 |
Correct |
78 ms |
93912 KB |
Output is correct |
8 |
Correct |
67 ms |
80672 KB |
Output is correct |
9 |
Correct |
67 ms |
78040 KB |
Output is correct |
10 |
Correct |
106 ms |
96388 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 |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
144012 KB |
Output is correct |
2 |
Correct |
240 ms |
155352 KB |
Output is correct |
3 |
Correct |
197 ms |
130252 KB |
Output is correct |
4 |
Correct |
198 ms |
129020 KB |
Output is correct |
5 |
Correct |
241 ms |
152600 KB |
Output is correct |
6 |
Correct |
62 ms |
77580 KB |
Output is correct |
7 |
Correct |
78 ms |
93912 KB |
Output is correct |
8 |
Correct |
67 ms |
80672 KB |
Output is correct |
9 |
Correct |
67 ms |
78040 KB |
Output is correct |
10 |
Correct |
106 ms |
96388 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 |
340 KB |
Output is correct |
14 |
Correct |
232 ms |
143968 KB |
Output is correct |
15 |
Correct |
249 ms |
155348 KB |
Output is correct |
16 |
Correct |
201 ms |
130372 KB |
Output is correct |
17 |
Correct |
205 ms |
129116 KB |
Output is correct |
18 |
Correct |
252 ms |
152440 KB |
Output is correct |
19 |
Correct |
62 ms |
77644 KB |
Output is correct |
20 |
Correct |
76 ms |
93968 KB |
Output is correct |
21 |
Correct |
67 ms |
80676 KB |
Output is correct |
22 |
Correct |
69 ms |
78096 KB |
Output is correct |
23 |
Correct |
104 ms |
96332 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
308 ms |
172492 KB |
Output is correct |
2 |
Correct |
335 ms |
185760 KB |
Output is correct |
3 |
Correct |
270 ms |
155596 KB |
Output is correct |
4 |
Correct |
276 ms |
154956 KB |
Output is correct |
5 |
Correct |
342 ms |
182508 KB |
Output is correct |
6 |
Correct |
61 ms |
77676 KB |
Output is correct |
7 |
Correct |
75 ms |
94024 KB |
Output is correct |
8 |
Correct |
65 ms |
80716 KB |
Output is correct |
9 |
Correct |
67 ms |
78780 KB |
Output is correct |
10 |
Correct |
119 ms |
103020 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2260 KB |
Output is correct |
2 |
Correct |
9 ms |
2388 KB |
Output is correct |
3 |
Correct |
6 ms |
1764 KB |
Output is correct |
4 |
Correct |
5 ms |
1364 KB |
Output is correct |
5 |
Correct |
8 ms |
2524 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
7400 KB |
Output is correct |
2 |
Correct |
15 ms |
7124 KB |
Output is correct |
3 |
Correct |
12 ms |
5972 KB |
Output is correct |
4 |
Correct |
12 ms |
5972 KB |
Output is correct |
5 |
Correct |
14 ms |
7280 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 |
852 KB |
Output is correct |
9 |
Correct |
2 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
2260 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
144012 KB |
Output is correct |
2 |
Correct |
240 ms |
155352 KB |
Output is correct |
3 |
Correct |
197 ms |
130252 KB |
Output is correct |
4 |
Correct |
198 ms |
129020 KB |
Output is correct |
5 |
Correct |
241 ms |
152600 KB |
Output is correct |
6 |
Correct |
62 ms |
77580 KB |
Output is correct |
7 |
Correct |
78 ms |
93912 KB |
Output is correct |
8 |
Correct |
67 ms |
80672 KB |
Output is correct |
9 |
Correct |
67 ms |
78040 KB |
Output is correct |
10 |
Correct |
106 ms |
96388 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 |
340 KB |
Output is correct |
14 |
Correct |
232 ms |
143968 KB |
Output is correct |
15 |
Correct |
249 ms |
155348 KB |
Output is correct |
16 |
Correct |
201 ms |
130372 KB |
Output is correct |
17 |
Correct |
205 ms |
129116 KB |
Output is correct |
18 |
Correct |
252 ms |
152440 KB |
Output is correct |
19 |
Correct |
62 ms |
77644 KB |
Output is correct |
20 |
Correct |
76 ms |
93968 KB |
Output is correct |
21 |
Correct |
67 ms |
80676 KB |
Output is correct |
22 |
Correct |
69 ms |
78096 KB |
Output is correct |
23 |
Correct |
104 ms |
96332 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 |
308 ms |
172492 KB |
Output is correct |
28 |
Correct |
335 ms |
185760 KB |
Output is correct |
29 |
Correct |
270 ms |
155596 KB |
Output is correct |
30 |
Correct |
276 ms |
154956 KB |
Output is correct |
31 |
Correct |
342 ms |
182508 KB |
Output is correct |
32 |
Correct |
61 ms |
77676 KB |
Output is correct |
33 |
Correct |
75 ms |
94024 KB |
Output is correct |
34 |
Correct |
65 ms |
80716 KB |
Output is correct |
35 |
Correct |
67 ms |
78780 KB |
Output is correct |
36 |
Correct |
119 ms |
103020 KB |
Output is correct |
37 |
Correct |
1 ms |
300 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
2260 KB |
Output is correct |
41 |
Correct |
9 ms |
2388 KB |
Output is correct |
42 |
Correct |
6 ms |
1764 KB |
Output is correct |
43 |
Correct |
5 ms |
1364 KB |
Output is correct |
44 |
Correct |
8 ms |
2524 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
2 ms |
852 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
6 ms |
1620 KB |
Output is correct |
53 |
Correct |
14 ms |
7400 KB |
Output is correct |
54 |
Correct |
15 ms |
7124 KB |
Output is correct |
55 |
Correct |
12 ms |
5972 KB |
Output is correct |
56 |
Correct |
12 ms |
5972 KB |
Output is correct |
57 |
Correct |
14 ms |
7280 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 |
852 KB |
Output is correct |
61 |
Correct |
2 ms |
1108 KB |
Output is correct |
62 |
Correct |
4 ms |
2260 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
3 ms |
1620 KB |
Output is correct |
66 |
Runtime error |
1216 ms |
524288 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |