| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 947134 | sandrofeiqrishvili | Knapsack (NOI18_knapsack) | C++14 | 97 ms | 3156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define int long long
const int N = 2005, inf=1e18;
vector <pair <int, int> > vec[N], g;
int dp[N];
int ans=0;
signed main(){
int s, n, v, w, r;
cin >> s >> n;
for(int i=1; i<=n; i++){
cin >> v >> w >> r;
vec[w].pb({v,r});
}
for (int i=1; i<=s; i++) {
sort(vec[i].begin(),vec[i].end());
reverse(vec[i].begin(), vec[i].end());
int tot = s/i;
for(int j=0; j<vec[i].size(); j++){
int val = vec[i][j].ff;
int raod = vec[i][j].ss;
for (int x=1; x<=min(raod, tot); x++) {
g.pb({i,val});
}
if(tot>=raod){
tot-=raod;
} else {
tot=0;
break;
}
}
}
n=g.size();
for(int i=1; i<=n; i++){
int w=g[i-1].ff;
int val=g[i-1].ss;
for(int j=s; j>=0; j--){
if (j>=w) dp[j]=max(dp[j], dp[j-w]+val);
ans=max(ans, dp[j]);
}
}
cout << ans;
}Compilation message (stderr)
| # | 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... | ||||
