제출 #963166

#제출 시각아이디문제언어결과실행 시간메모리
963166QuanmapneKnapsack (NOI18_knapsack)C++14
12 / 100
2 ms2652 KiB
#include<bits/stdc++.h> #define ll long long #define file "knapsack" using namespace std; const int maxN = 1e5 + 5; int t, n, s; int v[maxN], w[maxN], k[maxN], dp[2001]; vector< pair<int, int> > obj[maxN]; void solve(){ for (int i = 0; i <= s; ++i){ if (obj[i].size() == 0) continue; sort(obj[i].begin(), obj[i].end()); int id = 0; for (int j = 1; j * i <= s; ++j){ if (id == obj[i].size()) break; for (int f = s; f >= 0; --f){ if (f - i >= 0) dp[f] = max(dp[f], dp[f - i] + obj[i][id].first); } --obj[i][id].second; if (obj[i][id].second == 0) ++id; } } cout << dp[s]; } signed main(){ // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); t = 1; while (t){ cin >> s >> n; for (int i = 1; i <= n; ++i){ cin >> v[i] >> w[i] >> k[i]; obj[w[i]].push_back({v[i], k[i]}); } solve(); --t; } return 0; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |             if (id == obj[i].size())
      |                 ~~~^~~~~~~~~~~~~~~~
#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...