Submission #703290

#TimeUsernameProblemLanguageResultExecution timeMemory
703290pahnKnapsack (NOI18_knapsack)C++14
0 / 100
1086 ms724 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e3+5; const int M = 1e9+7; using vi = vector<int>; #define ll long long #define f first #define s second #define pii pair<int,int> #define pb push_back #define mp make_pair #define el '\n' ll s,n, a[mxN], b[mxN], c[mxN], dp[mxN][10005]; void solve() { cin >> s >> n; for (int i = 1; i <= n; ++i) cin >> b[i] >> a[i] >> c[i]; for (int i = 1; i <= n; ++i) { for (int w = 1; w <= s; ++w) { for (int j = 0; j <= c[i]; ++j) { if (j*a[i] <= w) dp[i][j] = max(dp[i][w], dp[i][w - j*a[i]] + j * b[i]); } } } cout << dp[n][s]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; // cin >> t; t = 1; 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...