Submission #527977

#TimeUsernameProblemLanguageResultExecution timeMemory
527977juankipediaKnapsack (NOI18_knapsack)C++14
73 / 100
1051 ms3880 KiB
# include <bits/stdc++.h> using namespace std; /*************************************************************************************/ # define endl "\n" # define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); typedef unsigned long long int ulli; typedef long long int lli; /*************************************JUANKIPEDIA*************************************/ const int MAXN = 100005; lli N, S, V[MAXN], W[MAXN], K[MAXN]; int main(){ io_boost; cin >> S >> N; for(lli i = 0; i < N; i++) cin >> V[i] >> W[i] >> K[i]; vector<lli> dp(S + 5, 0); for(lli i = 0; i < N; i++){ vector<lli> DP; DP = dp; for(lli j = 1; j <= K[i]; j++){ lli w = W[i] * j; if(w > S) break; for(lli k = S - w; k >= 0; k--){ DP[k + w] = max(DP[k + w], dp[k] + (V[i] * j)); } } for(int j = 0; j < dp.size(); j++) dp[j] = max(dp[j], DP[j]); } lli ans = 0; for(int i = 0; i <= S; i++){ ans = max(ans, dp[i]); } cout << ans << endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int j = 0; j < dp.size(); j++) dp[j] = max(dp[j], DP[j]);
      |                  ~~^~~~~~~~~~~
#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...