Submission #1081312

#TimeUsernameProblemLanguageResultExecution timeMemory
1081312erdemfurkanKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms348 KiB
#include "bits/stdc++.h" #define int long long using namespace std; int dp[2001][2001]; 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; 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 = -1; 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:32: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]
   32 |    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...