# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676071 | madtuber | Knapsack (NOI18_knapsack) | C++14 | 3 ms | 1876 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>
#define all(x) begin(x),end(x)
#define fir first
#define sec second
#define sz(x) x.size()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using pdb = pair<double,double>;
using pll = pair<ll,ll>;
using vll = vector<ll>;
const double EPS = (1e-6);
void setio(string s){
freopen((s + ".in").c_str(),"r",stdin);
freopen((s + ".out").c_str(),"w",stdout);
}
struct Item{
ll v, w, k;
};
const int MXN = 1e5+1;
const int MXS = 2001;
ll dp[MXN][MXS];
void solve(){
ll s, n;
cin >> s >> n;
vector<Item> a(n);
for(auto& i :a){
cin >> i.v >> i.w >> i.k;
}
for(int i{1}; i <= n; i++){
for(int j{}; j <= s; j++){
dp[i][j] = max(dp[i][j], dp[i-1][j]);
ll mx = min((s-j)/a[i-1].w, a[i-1].k);
dp[i][j+mx*a[i-1].w] = max(dp[i][j+mx*a[i-1].w], dp[i-1][j] + mx*a[i-1].v);
}
}
cout << dp[n][s];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--){
solve();
}
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... |