Submission #988323

#TimeUsernameProblemLanguageResultExecution timeMemory
988323thanhcodedaoKnapsack (NOI18_knapsack)C++14
73 / 100
1050 ms3676 KiB
/****ThanhCodeDao*****/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
typedef long long ll;
const ll maxN = 100005, modd = 1e9+7;
ll f[2005], w[maxN], v[maxN], k[maxN];
ll n,s;
void solve() {
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin >> s >> n;
    for(ll i = 1;i<=n;i++){
        cin >> v[i] >> w[i] >> k[i];
    }
    for(ll i = 1;i<=n;i++){
        for(ll j = s;j>=w[i];j--){
            for(ll t = 1;t<=k[i];t++){
                ll sl = t, add = sl * v[i], cost = sl * w[i];
                if(cost > j) break;
                f[j] = max(f[j],f[j-cost] + add);
            }
        }
    }
    cout << f[s];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    solve();
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...