제출 #1151340

#제출 시각아이디문제언어결과실행 시간메모리
1151340jeffffKnapsack (NOI18_knapsack)C++20
73 / 100
1093 ms16064 KiB
#include <bits/stdc++.h>
using namespace std;

int s, n, cnt;
long long v[100001*30], w[100001*30];
long long dp[2001];

int main(){
	scanf("%d%d", &s, &n);
	for(int i=1; i<=n; i++){
		//		scanf("%lld%lld%lld", &v[i], &w[i], &k[i]);
		long long vi, wi, ki;
		scanf("%lld%lld%lld", &vi, &wi, &ki);
		int t = 1;
		while (ki>=t) {
			v[++cnt]=vi*t;
			w[cnt]=wi*t;
			ki-=t;
			t*=2;
		}
		if(ki>0) {
			v[++cnt]=vi*ki;
			w[cnt]=wi*ki;
		}
	}
	for(int i=1; i<=cnt; i++){
		for(int j=s; j>=w[i]; j--){
			dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
		}
	}
	
	printf("%lld", dp[s]);
}

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         scanf("%d%d", &s, &n);
      |         ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:13:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |                 scanf("%lld%lld%lld", &vi, &wi, &ki);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...