Submission #1163652

#TimeUsernameProblemLanguageResultExecution timeMemory
1163652ramalzaherKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms2632 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 10000000; int dp[N], w[N], v[N] , k[N]; void solve() { int n, m; cin >> m >> n; for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = m; j > 0; j--) { int z = 1; while (j - z*w[i] >= 0 && z<=k[i]) { dp[j] = max( dp[j], (dp[j - z * w[i]] + z * v[i])); z++; } } } cout << dp[m] << endl; } main() { // #ifndef ONLINE_JUDGE // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

knapsack.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | 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...