#include <bits/stdc++.h>
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 |
Incorrect |
219 ms |
143832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
219 ms |
143832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
292 ms |
143968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
219 ms |
143832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |