Submission #975908

#TimeUsernameProblemLanguageResultExecution timeMemory
975908vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
1040 ms2512 KiB
#include <bits/stdc++.h>
using namespace std;
#define futaba ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rio return 0;
#define ll long long

// Fun things are fun. //

ll dp[1005][2005], v[1005], k[1005];
int w[100005];

int main() {
    /* freopen(".txt", "r", stdin);
    freopen(".txt", "w", stdout); */
    futaba
    int s, n;
    cin >> s >> n;
    for(int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i];
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= s; j++) {
            for(int l = 0; l <= k[i]; l++) {
                if(j >= (w[i] * l)) dp[i][j] = max(dp[i][j], dp[i - 1][j - (w[i] * l)] + (l * v[i]));
            }
        }
    }
    cout << dp[n][s] << '\n';
    rio
}
#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...