이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <cstring>
using namespace std;
#define problemname "ojuzknapsack"
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define MOD (int)1e9+7
#define ll long long
#define ff first
#define ss second
bool ckmin(int& a, int b) {return a>b?a=b,true:false;}
bool ckmax(int& a, int b) {return a<b?a=b,true:false;}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen (problemname ".in", "r", stdin); freopen(problemname ".out", "w", stdout);
int s,n; cin>>s>>n;
vector<vector<pii>> stuff(s+1);
for(int i=0; i<n; i++) {
int v,w,k;
cin>>v>>w>>k;
stuff[w].pb({v,k});
}
for(int i=0; i<=s; i++) {
sort(stuff[i].begin(), stuff[i].end(), greater<pii>());
}
int dp[s+3]; memset(dp, 0xc0, sizeof(int)*(s+1));
dp[0]=0;
for(int i=0; i<=s; i++) {
int amntused=0; // amount used by objects with weight i
for(pii obj : stuff[i]) {
for(int cnt=0; cnt<obj.ss; cnt++) {
amntused+=i;
if(amntused>s) break;
for(int thres=s; thres>=amntused; thres--) {
ckmax(dp[thres], dp[thres-i]+obj.ff);
}
}
if(amntused>s) break;
}
}
int ans=0;
for(int i=0; i<=s; i++) {
ckmax(ans, dp[i]);
}
cout<<ans<<endl;
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... |