Submission #970473

#TimeUsernameProblemLanguageResultExecution timeMemory
970473v_mateiKnapsack (NOI18_knapsack)C++17
73 / 100
1067 ms1440 KiB
#include <bits/stdc++.h> #include <vector> #define ll long long #define ull unsigned long long #define pii std::pair<int, int> #define IO (std::string) "" std::ifstream fin(IO + ".in"); std::ofstream fout(IO + ".out"); #define NMAX 100'007 #define SMAX 2007 int n, s; int v[NMAX], w[NMAX], k[NMAX]; std::vector<int> dp; void citire() { std::cin >> s >> n; for (int i = 1; i <= n; i++) std::cin >> v[i] >> w[i] >> k[i]; dp.resize(s + 1); } int main() { citire(); for (int i = 1; i <= n; i++) { for (int j = s; j >= 0; j--) { for (int x = 0; j - w[i] * x >= 0 && x <= k[i]; x++) { dp[j] = std::max(dp[j], dp[j - x * w[i]] + x * v[i]); } } } std::cout << dp[s]; 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...