Submission #841742

#TimeUsernameProblemLanguageResultExecution timeMemory
841742digiEnceladusKnapsack (NOI18_knapsack)C++17
73 / 100
135 ms262144 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second using namespace std; const int N = 1e5, S = 2e3; int n, s, k; ll F[N+1][S+1], V[N+1], W[N+1], K[N+1]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); 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 = 1; j <= s; j++) { F[i][j] = F[i-1][j]; if (j - W[i] >= 0) for (int x = 1; x <= min(j/W[i], K[i]); x++) F[i][j] = max(F[i][j], F[i-1][j - x*W[i]] + x*V[i]); } cout << F[n][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...