제출 #1018251

#제출 시각아이디문제언어결과실행 시간메모리
1018251arkash707Knapsack (NOI18_knapsack)C++17
37 / 100
1080 ms2820 KiB
#include<iostream> #include<string> #include<algorithm> #include<unordered_set> #include<unordered_map> #include<vector> #define ll long long using namespace std; int mod = 1000000007; int s, n; const int N = 100001; vector<ll> c(N, 0); vector<ll> w(N, 0); vector<ll> q(N, 0); long long solve() { vector<ll> dp(s+1, -1); ll ans = 0; dp[0] = 0; for (int i=1; i<=n; i++) { for (int j=s; j>=0; j--) { //buy from 0 to q[i] of good i for (int k=0; k<=q[i]; k++) { if (j-k*w[i] < 0 || dp[j-k*w[i]] == -1) continue; dp[j] = max(dp[j], dp[j-k*w[i]] + c[i] * k); } ans = max(ans, dp[j]); } } return ans; } int main() { cin >> s >> n; for (int i=1; i<=n; i++) cin >> c[i] >> w[i] >> q[i]; cout << solve() << "\n"; }
#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...