Submission #1084021

#TimeUsernameProblemLanguageResultExecution timeMemory
1084021kitkat12Knapsack (NOI18_knapsack)C++14
73 / 100
211 ms262144 KiB
// https://oj.uz/problem/view/NOI18_knapsack // Created on: 2024-09-04 21:21:52 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define mp make_pair #define pb push_back #define F first #define S second #define debug(x) std::cout << #x << ": " << x << "\n" #define all(v) v.begin(), v.end() #define li(i,a,b) for (int (i) = (a); (i) < (b); (i)++) #define endl '\n' #define mem(name,val) memset(name,val,sizeof(name)) #define min(a,b) (a<=b ? a : b) #define max(a,b) (a>=b ? a : b) //using u64 = uint64_t; //using u128 = __uint128_t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int s,n; cin>>s>>n; int w[n], v[n], k[n]; li(i,0,n){ cin>>v[i]>>w[i]>>k[i]; } int dp[s+2][n+2]; mem(dp,0); for(int i = 1; i<=s; i++){ for(int j = 0; j<n ; j++){ for(int l = 0; l<=k[j]; l++){ if(j == 0){ if(i - w[j]*l >= 0){ dp[i][j] = max(dp[i][j], l * v[j]); continue; } else{ break; } } if(i - w[j]*l >= 0) dp[i][j] = max(dp[i][j], dp[i - w[j]*l][j-1] + l * v[j]); else{ break; } } } } cout<<dp[s][n-1]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:13:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   13 | #define li(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
      |                            ^
knapsack.cpp:28:5: note: in expansion of macro 'li'
   28 |     li(i,0,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...