# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030483 | LmaoLmao | Knapsack (NOI18_knapsack) | C++14 | 3 ms | 604 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;
using ll = long long;
using ii = pair<int, int>;
using aa = array<int,3>;
const int N = 1e6+5;
const int INF = 1e9;
struct goods
{
double avg;
ll v;
int w;
ll k;
};
bool cmp(goods a,goods b) {
return (a.avg<b.avg);
}
ll dp[2005];
goods a[100005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n,s;
cin >> s >> n;
for(int i=1;i<=s;i++) {
dp[i]=0;
}
dp[0]=0;
for(int i=1;i<=n;i++) {
cin >> a[i].v >> a[i].w >> a[i].k;
a[i].avg=((a[i].v*1.0)/(a[i].w*1.0));
}
sort(a+1,a+1+n,cmp);
ll ans=0;
for(int i=1;i<=n;i++) {
for(ll j=s;j>0;j--) {
int m=min(j/a[i].w,a[i].k);
if(j>=a[i].w) dp[j]=max(dp[j],dp[j-(m*a[i].w)]+m*a[i].v);
ans=max(ans,dp[j]);
//cout << dp[j] << ' ';
}
//cout << endl;
}
cout << ans;
return 0;
}
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... |