Submission #1084022

#TimeUsernameProblemLanguageResultExecution timeMemory
1084022kitkat12Knapsack (NOI18_knapsack)C++14
73 / 100
1093 ms2764 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]; mem(dp,0); li(i,0,n){ for(int j = s; j>=1; j--){ li(l,0,k[i]+1){ if(j - l * w[i] >= 0){ if(i == 0){ dp[j] = max(dp[j] , l * v[i]); } else dp[j] = max(dp[j], dp[j-l*w[i]] + l * v[i]); } else{ break; } } } } cout<<dp[s]; 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){
      |     ^~
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:34:5: note: in expansion of macro 'li'
   34 |     li(i,0,n){
      |     ^~
knapsack.cpp:13:28: warning: unnecessary parentheses in declaration of 'l' [-Wparentheses]
   13 | #define li(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
      |                            ^
knapsack.cpp:36:13: note: in expansion of macro 'li'
   36 |             li(l,0,k[i]+1){
      |             ^~
#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...