이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |