제출 #1023715

#제출 시각아이디문제언어결과실행 시간메모리
1023715vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Item { int value; int weight; int count; }; int main() { int N, S; cin >> N >> S; vector<Item> items(N); for (int i = 0; i < N; ++i) { cin >> items[i].value >> items[i].weight >> items[i].count; } vector<long long> dp(S + 1, 0); for (int i = 0; i < N; ++i) { int v = items[i].value; int w = items[i].weight; int k = items[i].count; for (int j = 1; k > 0; j <<= 1) { int count = min(j, k); k -= count; long long weight = 1LL * w * count; long long value = 1LL * v * count; for (int x = S; x >= weight; --x) { dp[x] = max(dp[x], dp[x - weight] + value); } } } cout << dp[S] << endl; 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...