Submission #901343

#TimeUsernameProblemLanguageResultExecution timeMemory
901343vjudge1Knapsack (NOI18_knapsack)C++14
49 / 100
1064 ms1996 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define pll pair<ll,ll> #define pii pair<int,int> #define vi vector<int> #define vll vector<ll> ll dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; ll dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const ll INF = 1e9 + 16, M = 1e9 + 7, MaxN = 2e5 +6; void solve(int tc) { int k, n; cin >> k >> n; vector<vll > dp(n + 1, vll(k + 1, 0)); for (int i = 0; i < n; ++i) { ll v, w, c; cin >> v >> w >> c; for (ll cnt = 0; cnt <= c; ++cnt) { for (int j = k; j >= 0; --j) { if (j - w * cnt >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w * cnt] + v * cnt); else break; } } } cout << dp[n][k] << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int tt = 1; // cin >> tt; for (int tc = 1; tc <= tt; tc++) { solve(tc); } 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...