Submission #983333

#TimeUsernameProblemLanguageResultExecution timeMemory
983333fasgqwrgqwgKnapsack (NOI18_knapsack)C++17
17 / 100
3 ms3672 KiB
#include <bits/stdc++.h> using namespace std; // #ifndef ONLINE_JUDGE // #include "/debug.cpp" // #else // #define debug(...) 0 // #endif #define yes cout << "YES" << '\n' #define no cout << "NO" << '\n' #define pll pair<long long, long long> #define pii pair<int, int> #define newl "\n" #define vt vector #define ar array #define LOOP(iter) iter.begin(), iter.end() #define FOR(i, n) for (ll i = 0; i < n; i++) #define FORK(i, n, k) for (ll i = k; i < n; i++) #define ll long long #define ld long double #define sza(x) ((int)x.size()) #define all(a) (a).begin(), (a).end() #define pb(x) push_back(x) #define ff first #define ss second #define CEIL(a, b) ((a + b - 1) / b) #define fileio(in, out) \ freopen(in, "r", stdin); \ freopen(out, "w", stdout) const int MAX_N = 1e5 + 5; const ll MOD_INV = 500000004; const ll MOD = 1e9 + 7; const ll INF = 10e9 + 5; const ld EPS = 1e-9; template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } void solve() { ll n, s; cin >> s >> n; vector<ll> v(n+1), w(n+1), k(n+1); for (int i = 0; i < n; i++) { cin >> v[i+1]; cin >> w[i+1]; cin >> k[i+1]; } vector<vector<pll>> dp(n + 1, vector<pll>(s + 1, {0, 0})); for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= s; j++) { dp[i][j] = dp[i - 1][j]; dp[i][j].ss = 0; if (j - w[i] >= 0) { if (dp[i][j].ff < dp[i - 1][j - w[i]].ff + v[i]) { dp[i][j].ff = dp[i - 1][j - w[i]].ff + v[i]; dp[i][j].ss = 1; } // if (dp[i][j].ff < dp[i][j - w[i]].ff and dp[i][j - w[i]].ss + 1 <= k[i]) { // dp[i][j].ff = dp[i][j - w[i]].ff + v[i]; // dp[i][j].ss++; // } } } } cout << dp[n][s].ff; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#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...