Submission #523922

#TimeUsernameProblemLanguageResultExecution timeMemory
523922_karan_gandhiKnapsack (NOI18_knapsack)C++17
73 / 100
1095 ms3520 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(v) v.begin(), v.end() #define endl '\n' #define pl(var) " [" << #var << ": " << (var) << "] " #define value 0 #define weight 1 #define number 2 ll int mod = 1e9 + 7; void solve() { ll int s, n; cin >> s >> n; vector<array<ll int, 3>> arr; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; if (b > s) continue; arr.push_back({a, b, c}); } vector<ll int> dp(s + 1, 0); for (int i = 0; i < n; i++) { for (int j = s; j >= 1; j--) { ll int cur = 1; // here I will have O(s^2) making the total complexity O(N * S^2) while ((j - (arr[i][weight] * cur)) >= 0 && cur <= arr[i][number]) { dp[j] = max(dp[j], dp[j - arr[i][weight] * cur] + arr[i][value] * cur); cur++; } } } cout << dp[s] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // int t; cin >> t; // while (t--) solve(); 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...