제출 #886799

#제출 시각아이디문제언어결과실행 시간메모리
886799xn_17Knapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
//oj.uz--NOI18_KNAPSACK //USACO Knapsack DP #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair int main() { int s,n; cin >> s >> n; vector<pair<ll,ll>> weights[s+1]; pair<int,pair<int,int>> items[n]; for(int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; //items[i] = mp(w, mp(v, k)); if(w <= s) { weights[w].pb(mp(v,k)); } } for(int i = 0; i <= s; i++) { sort(weights[i].begin(), weights[i].end(), greater()); } ll dp[s+1]; for(int i = 0; i <= s; i++) { dp[i] = 0; } for(int w = 1; w <= s; w++) { int i = 0; int tot = 0; while(i < weights[w].size() && tot <= s) { ll v,k; tie(v,k) = weights[w][i]; for(int j = s; j >= w; j--) { dp[j] = max(dp[j], dp[j-w] + v); } weights[w][i].second -= 1; if(k == 1) { i++; } tot += w; } } cout << dp[s]; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:31:59: error: missing template arguments before '(' token
   31 |         sort(weights[i].begin(), weights[i].end(), greater());
      |                                                           ^
knapsack.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         while(i < weights[w].size() && tot <= s)
      |               ~~^~~~~~~~~~~~~~~~~~~
knapsack.cpp:16:29: warning: unused variable 'items' [-Wunused-variable]
   16 |     pair<int,pair<int,int>> items[n];
      |                             ^~~~~