제출 #866917

#제출 시각아이디문제언어결과실행 시간메모리
866917iskhakkutbilimKnapsack (NOI18_knapsack)C++17
73 / 100
1026 ms4048 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 1e9 + 7;
const int N = 1e5;

main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
	int s, n; cin >> s >> n;
	vector<int> v(n+1), w(n+1), k(n+1);
	vector<int> dp(s+1, LLONG_MIN);
	dp[0] = 0;
	for(int i = 1;i <= n; i++){
		cin >> v[i] >> w[i] >> k[i];
	}
	for(int i = 1;i <= n; i++){
		for(int round = 1; round * w[i] <= s && round <= k[i]; round++){
			for(int d = s; d - w[i] >= 0; d--){
				dp[d] = max(dp[d], dp[d-w[i]] + v[i]);
			}
		}
	}
	int ans = LLONG_MIN;
	for(int i = 0;i <= s; i++){
		ans = max(ans, dp[i]);
	}
	cout << ans;
	return 0;
}

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

knapsack.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
#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...