Submission #1091504

#TimeUsernameProblemLanguageResultExecution timeMemory
1091504diponkinuKnapsack (NOI18_knapsack)C++14
100 / 100
84 ms4908 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int T = 2005; vector<pair<int,int>> a[T]; int dp[T]; signed main(){ // freopen("feast.in", "r", stdin); // freopen("feast.out", "w", stdout); int n,s; cin >> s >> n; for(int i = 0; i < n; i++){ int v,w,k; cin >> v >> w >> k; a[w].push_back({v,k}); } for(int i = 1; i <= T; i++ ){ // if(a[i].size()<1)continue; sort(a[i].rbegin(), a[i].rend() ); // cout << a[i][0].first << " "; int p = 0; for(int j = 0; j < s/i; j++){ if(p>=a[i].size())break; int tempvalue = a[i][p].first; for(int o = s; o >= 0; o--){ if(o+i <= s)dp[o+i] = max(dp[o+i],dp[o] + tempvalue); } a[i][p].second--; if(a[i][p].second == 0)p++; } } cout << dp[s]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:25:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |    if(p>=a[i].size())break;
      |       ~^~~~~~~~~~~~~
#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...