제출 #970983

#제출 시각아이디문제언어결과실행 시간메모리
970983handlenameKnapsack (NOI18_knapsack)C++17
100 / 100
44 ms3160 KiB
#include <bits/stdc++.h> using namespace std; int s,n; int memo[2001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>s>>n; multiset<int> arr[s+1]; for (int i=0;i<n;i++){ int a,b,c; cin>>a>>b>>c; c=min(c,s/b); while (c>0 && arr[b].size()+1<=s/b){ arr[b].insert(a); c--; } while (c>0 && a>(*arr[b].begin())){ arr[b].erase(arr[b].begin()); arr[b].insert(a); c--; } } for (int b=0;b<=s;b++){ for (auto a:arr[b]){ for (int j=s-b;j>=0;j--){ memo[j+b]=max(memo[j+b],memo[j]+a); } } } cout<<memo[s]; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:14:38: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |         while (c>0 && arr[b].size()+1<=s/b){
      |                       ~~~~~~~~~~~~~~~^~~~~
#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...