Submission #490618

#TimeUsernameProblemLanguageResultExecution timeMemory
490618lolipopKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
//looking for 49 points(subtasks 1 - 3) #include<bits/stdc++.h> using namespace std; #define int long long using ll = long long; using ii = pair <int, int>; const int maxn = 105, maxk = 15, maxs = 2005; int n, s; int V[maxn], W[maxn], K[maxs]; int dp[maxn][maxs]; main () { ios::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("in.txt", "r", stdin); #endif cin >> s >> n; for (int i = 1; i <= n; ++i) { cin >> V[i] >> W[i] >> K[i]; } int ans = 0; if (n == 1) { int take = s / w[0]; ans = take > K[0] ? K[0] * v[0] : take * v[0]; cout << ans; return 0; } for (int i = 1; i <= n; ++i) { for (int j = 0; j <= s; ++j) { for (int k = 0; k <= K[i]; ++k) { int tot = k * W[i]; if (j - tot >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - tot] + k * V[i]); dp[i][j] = max(dp[i][j], dp[i - 1][j]); ans = max(ans, dp[i][j]); } } } cout << ans; return 0; } /* array bound? overflow? print newline after every cases idea correct? */

Compilation message (stderr)

knapsack.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main () {
      | ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:29:20: error: 'w' was not declared in this scope
   29 |     int take = s / w[0];
      |                    ^
knapsack.cpp:30:32: error: 'v' was not declared in this scope
   30 |     ans = take > K[0] ? K[0] * v[0] : take * v[0];
      |                                ^