제출 #860087

#제출 시각아이디문제언어결과실행 시간메모리
860087pete555Knapsack (NOI18_knapsack)C++17
100 / 100
136 ms35156 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define s second
#define f first
int main(){
	int s, n; 
	cin >> s >> n;
	map<int, vector<pair<int,int>>> items;
	for(int i=0; i<n; i++){
		int v, w, k; cin >> v >> w >> k;
		items[w].push_back({v, k});
	}
	vector<vector<ll>> dp(items.size()+1, vector<ll>(s+1));
	dp[0][0] = 0;
	int at = 1;
	for(auto item: items){
		sort(item.s.begin(), item.s.end(), greater<pair<int,int>>());
		for(int i=0; i<=s; i++){
			dp[at][i] = dp[at-1][i];
			int copy = 0, type_at = 0, curr_used = 0;
			ll profit = 0;
			while((copy+1)*item.first <= i and type_at < item.s.size()){
				copy++;
				profit += item.s[type_at].f;
				dp[at][i] = max(dp[at][i], dp[at-1][i-copy*item.f] + profit);
				
				curr_used++;
				if(curr_used == item.s[type_at].s){
					curr_used = 0;
					type_at++;
				}
			}
		}
		at++;
	}
	cout << dp[items.size()][s];
}

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |    while((copy+1)*item.first <= i and type_at < item.s.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...