이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define db(x) cerr << #x <<":"<<x<<" "
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int N=1e5+2;
typedef array<int,3>item ;
int main(){
int n, kg; cin>>kg>>n;
vector<item> a(n+1);
unordered_map<int,vector<item>> byWeight;
for(int i=1;i<=n;++i){
cin>>a[i][0]>>a[i][1]>>a[i][2];
byWeight[a[i][1]].push_back(a[i]);
// auto[v,w,k]=a[i];
// 0 1 2
}
int i=0;
vector<vector<int>> bst(byWeight.size()+1,vector<int>(kg+1,INT32_MIN));
bst[0][0]=0;
for(auto &[w, itms]:byWeight){
++i;
sort(itms.begin(), itms.end(), std::greater<item>());
db(w);
for(int j=0;j<=kg;++j){
bst[i][j]=bst[i-1][j];
int profit=0;
for(int curr=0,r=1,currUsed=0; curr<(int)itms.size() and r*w<=j; ++r){
profit+=itms[curr][0];
++currUsed;
bst[i][j]=max(
bst[i][j],
bst[i-1][j-r*w]+profit
);
if(currUsed==itms[curr][2]){
++curr;
currUsed=0;
}
}
}
}
int ans=0;
for(int i=1;i<=kg;++i)
ans=max(ans,bst[byWeight.size()][i]);
cout<<ans;
}
# | 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... |