Submission #1094983

#TimeUsernameProblemLanguageResultExecution timeMemory
1094983vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
51 ms4444 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define inf32 ((int)1e9 + 7) #define inf64 ((long long)1e18 + 7) #define MASK32(x) (1 << (x)) #define MASK64(x) (1LL << (x)) #define BIT(mask, i) (((mask) >> (i)) & 1) #define all(a) begin(a), end(a) #define isz(a) ((int)a.size()) const int N = 1e5 + 1, S = 2e3 + 1; struct Item { int v, w, k; bool operator<(const Item& rhs) { return v > rhs.v; } }; vector<Item> W[S]; int dp[S]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; for(int i = 1, v, w, k; i <= n; ++i) { cin >> v >> w >> k; W[w].push_back({v, w, k}); } vector<Item> v; for(int i = 1; i <= s; ++i) { int cnt = 0; sort(all(W[i])); for(const Item& it : W[i]) { v.push_back({it.v, i, min((s - cnt) / i + 1, it.k)}); cnt += i * min((s - cnt) / i + 1, it.k); if(cnt > s) break; } } for(Item& it : v) { for(int i = 1; i <= it.k; ++i) for(int w = s; w >= it.w; --w) dp[w] = max(dp[w], dp[w - it.w] + it.v); } 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...