제출 #1135928

#제출 시각아이디문제언어결과실행 시간메모리
1135928ashokanrKnapsack (NOI18_knapsack)C++20
73 / 100
1093 ms18556 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5+5; int a[N],b[N],k[N]; int dp[N]; vector <int> W,V; main() { ios_base::sync_with_stdio(0); int n,s; cin >> s >> n; for(int i=1;i<=n;++i) { cin >> b[i] >> a[i] >> k[i]; k[i] = min(k[i],s/a[i]); } W.push_back(0); V.push_back(0); for(int i=1;i<=n;i++) { int pw = 1; while (k[i] >= pw ) { k[i] -= pw; if (a[i] * pw > s) break; W.push_back(a[i] * pw); V.push_back(b[i] * pw); pw *= 2; } if (k[i] > 0) { if (a[i] * k[i] > s) continue; W.push_back(a[i] * k[i]); V.push_back(b[i] * k[i]); } } // for(auto x:W) cout << x << " "; // cout << endl; // for(auto x:V) cout << x << " "; for(int i=1;i<=W.size()-1;++i) { for(int j=s;j;--j) { if (j >= W[i]) dp[j] = max(dp[j],dp[j-W[i]] + V[i]); } } cout << *max_element(dp,dp+s+1); }

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

knapsack.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | 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...