Submission #1064303

#TimeUsernameProblemLanguageResultExecution timeMemory
1064303vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
130 ms262144 KiB
#include<bits/stdc++.h> #define int long long #define endl '\n' using namespace std; const int maxn = 1e5 + 2; int n,m; int a[maxn]; int b[maxn]; int c[maxn]; int dp[maxn][2005]; int res[maxn]; main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> m >> n; for (int i = 1; i <= n; i++) { cin >> b[i] >> a[i] >> c[i]; } for (int i = 1; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = dp[i-1][j]; for (int k = 0; k <= min(c[i],j/a[i]); k++) { if (dp[i-1][j-k*a[i]]+b[i]*k > dp[i][j]) { //trace[i][j] = k; dp[i][j] = dp[i-1][j-k*a[i]]+b[i]*k; } } } } cout << dp[n][m]; }

Compilation message (stderr)

knapsack.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      | ^~~~
#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...