Submission #1081323

#TimeUsernameProblemLanguageResultExecution timeMemory
1081323erdemfurkanKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms348 KiB
#include "bits/stdc++.h" #define int long long using namespace std; int dp[2005][2005]; signed main() { int s, n; cin >> s >> n; map<int,vector<pair<int,int>>> gruplar; for(int i = 0; i < n; i++) { int vi, wi, ki; cin >> vi >> wi >> ki; if(ki > 0 && wi <= s) gruplar[wi].push_back({vi, ki}); } for(auto x : gruplar) { sort(x.second.begin(), x.second.end(), greater<pair<int,int>>()); } // dp[i][j] ilk i grubu kullanarak j ağırlık kullanarak elde edebileceğim en fazla değer dp[0][0] = 0; int i = 1; for(auto x : gruplar) { int agirlik = x.first; // gruptakilerin ağırlığı vector<pair<int,int>> grup = x.second; // {değer, kaç tane olduğu} for(int w = 0; w <= s; w++) { int j = 0; int k = 0; int deger = 0; int kk = 0; dp[i][w] = dp[i-1][w]; while(j < grup.size() && (kk+1)*agirlik <= s) { kk++; k++; deger += grup[j].first; if(w - kk * agirlik >= 0) dp[i][w] = max(dp[i][w], dp[i-1][w-kk*agirlik]+deger); if(k == grup[j].second) { j++; k = 0; } } } i++; } int mx = 0; for(int j = 0; j <= s; j++) { mx = max(dp[i-1][j], mx); } cout << mx << endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:33:12: 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]
   33 |    while(j < grup.size() && (kk+1)*agirlik <= s) {
      |          ~~^~~~~~~~~~~~~
#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...