#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(vi) dp(n+1),nedp;
dp[0]={0};
rep(i,n){
nedp=dp;
auto [d,w]=a[i];
rep(j,d){
if(!sz(dp[j])) continue;
for(auto s:dp[j]){
nedp[j+1].pb(s+w);
}
}
rep(j,n+1){
sort(all(nedp[j]));
while(sz(nedp[j])>k){
nedp[j].pop_back();
}
}
swap(dp,nedp);
}
vp pns;
for(int j=n;j>=1;j--){
reverse(all(dp[j]));
while(min(k,sz(dp[j]))){
pns.pb({j,dp[j].back()});
dp[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 |
46 ms |
620 KB |
Output is correct |
2 |
Correct |
48 ms |
468 KB |
Output is correct |
3 |
Correct |
40 ms |
504 KB |
Output is correct |
4 |
Correct |
52 ms |
468 KB |
Output is correct |
5 |
Correct |
52 ms |
504 KB |
Output is correct |
6 |
Correct |
22 ms |
340 KB |
Output is correct |
7 |
Correct |
23 ms |
340 KB |
Output is correct |
8 |
Correct |
21 ms |
428 KB |
Output is correct |
9 |
Correct |
20 ms |
340 KB |
Output is correct |
10 |
Correct |
29 ms |
448 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
620 KB |
Output is correct |
2 |
Correct |
48 ms |
468 KB |
Output is correct |
3 |
Correct |
40 ms |
504 KB |
Output is correct |
4 |
Correct |
52 ms |
468 KB |
Output is correct |
5 |
Correct |
52 ms |
504 KB |
Output is correct |
6 |
Correct |
22 ms |
340 KB |
Output is correct |
7 |
Correct |
23 ms |
340 KB |
Output is correct |
8 |
Correct |
21 ms |
428 KB |
Output is correct |
9 |
Correct |
20 ms |
340 KB |
Output is correct |
10 |
Correct |
29 ms |
448 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
46 ms |
512 KB |
Output is correct |
15 |
Correct |
49 ms |
532 KB |
Output is correct |
16 |
Correct |
45 ms |
468 KB |
Output is correct |
17 |
Correct |
43 ms |
480 KB |
Output is correct |
18 |
Correct |
51 ms |
536 KB |
Output is correct |
19 |
Correct |
26 ms |
340 KB |
Output is correct |
20 |
Correct |
27 ms |
340 KB |
Output is correct |
21 |
Correct |
26 ms |
440 KB |
Output is correct |
22 |
Correct |
24 ms |
428 KB |
Output is correct |
23 |
Correct |
27 ms |
468 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 |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
536 KB |
Output is correct |
2 |
Correct |
79 ms |
592 KB |
Output is correct |
3 |
Correct |
57 ms |
564 KB |
Output is correct |
4 |
Correct |
54 ms |
552 KB |
Output is correct |
5 |
Correct |
62 ms |
528 KB |
Output is correct |
6 |
Correct |
20 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
352 KB |
Output is correct |
8 |
Correct |
22 ms |
340 KB |
Output is correct |
9 |
Correct |
20 ms |
340 KB |
Output is correct |
10 |
Correct |
29 ms |
496 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 |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1236 KB |
Output is correct |
2 |
Correct |
9 ms |
1108 KB |
Output is correct |
3 |
Correct |
5 ms |
1108 KB |
Output is correct |
4 |
Correct |
5 ms |
980 KB |
Output is correct |
5 |
Correct |
8 ms |
1244 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
596 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 |
1068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
704 KB |
Output is correct |
2 |
Correct |
12 ms |
608 KB |
Output is correct |
3 |
Correct |
13 ms |
596 KB |
Output is correct |
4 |
Correct |
9 ms |
592 KB |
Output is correct |
5 |
Correct |
12 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
224 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
620 KB |
Output is correct |
2 |
Correct |
48 ms |
468 KB |
Output is correct |
3 |
Correct |
40 ms |
504 KB |
Output is correct |
4 |
Correct |
52 ms |
468 KB |
Output is correct |
5 |
Correct |
52 ms |
504 KB |
Output is correct |
6 |
Correct |
22 ms |
340 KB |
Output is correct |
7 |
Correct |
23 ms |
340 KB |
Output is correct |
8 |
Correct |
21 ms |
428 KB |
Output is correct |
9 |
Correct |
20 ms |
340 KB |
Output is correct |
10 |
Correct |
29 ms |
448 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
46 ms |
512 KB |
Output is correct |
15 |
Correct |
49 ms |
532 KB |
Output is correct |
16 |
Correct |
45 ms |
468 KB |
Output is correct |
17 |
Correct |
43 ms |
480 KB |
Output is correct |
18 |
Correct |
51 ms |
536 KB |
Output is correct |
19 |
Correct |
26 ms |
340 KB |
Output is correct |
20 |
Correct |
27 ms |
340 KB |
Output is correct |
21 |
Correct |
26 ms |
440 KB |
Output is correct |
22 |
Correct |
24 ms |
428 KB |
Output is correct |
23 |
Correct |
27 ms |
468 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 |
212 KB |
Output is correct |
27 |
Correct |
59 ms |
536 KB |
Output is correct |
28 |
Correct |
79 ms |
592 KB |
Output is correct |
29 |
Correct |
57 ms |
564 KB |
Output is correct |
30 |
Correct |
54 ms |
552 KB |
Output is correct |
31 |
Correct |
62 ms |
528 KB |
Output is correct |
32 |
Correct |
20 ms |
340 KB |
Output is correct |
33 |
Correct |
25 ms |
352 KB |
Output is correct |
34 |
Correct |
22 ms |
340 KB |
Output is correct |
35 |
Correct |
20 ms |
340 KB |
Output is correct |
36 |
Correct |
29 ms |
496 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 |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1236 KB |
Output is correct |
41 |
Correct |
9 ms |
1108 KB |
Output is correct |
42 |
Correct |
5 ms |
1108 KB |
Output is correct |
43 |
Correct |
5 ms |
980 KB |
Output is correct |
44 |
Correct |
8 ms |
1244 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
2 ms |
596 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 |
1068 KB |
Output is correct |
53 |
Correct |
11 ms |
704 KB |
Output is correct |
54 |
Correct |
12 ms |
608 KB |
Output is correct |
55 |
Correct |
13 ms |
596 KB |
Output is correct |
56 |
Correct |
9 ms |
592 KB |
Output is correct |
57 |
Correct |
12 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
352 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
2 ms |
340 KB |
Output is correct |
62 |
Correct |
4 ms |
340 KB |
Output is correct |
63 |
Correct |
0 ms |
224 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
3 ms |
460 KB |
Output is correct |
66 |
Execution timed out |
5048 ms |
26904 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |