Submission #890692

#TimeUsernameProblemLanguageResultExecution timeMemory
890692nikhilg2121Knapsack (NOI18_knapsack)C++17
73 / 100
189 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<vi> vvi; typedef vector<pll> vll; typedef vector<vl> vvl; #define fori(i, n) for (int i = 0; i < n; i++) #define ford(i, n) for (int i = n - 1; i >= 0; i--) #define rep(i, a, b) for (int i = a; i <= b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define trav(x, a) for (auto &x : a) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define endl '\n' #define sz(a) (int)(a).size() #define fi first #define se second #define mp make_pair void solve(){ int s,n; cin>>s>>n; vi v(n); vi w(n); vi k(n); fori(i,n){ cin>>v[i]>>w[i]>>k[i]; } vvi dp(n+1,vi(s+1,0)); fori(i,n+1){ dp[i][0] = 0; } rep(i,1,n){ rep(j,1,s){ int t=0; dp[i][j] = dp[i-1][j]; while(t<=k[i-1] && j-t*w[i-1]>=0){ dp[i][j] = max( dp[i][j], dp[i-1][j-t*w[i-1]] + t*v[i-1]); t++; } } } int ans=0; fori(i,s+1){ ans = max(ans,dp[n][i]); } // fori(i,n+1){ // fori(j,s+1){ // cout<<dp[i][j]<<" "; // } // cout<<endl; // } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; // cin >> t; while (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...