제출 #716626

#제출 시각아이디문제언어결과실행 시간메모리
716626faricaKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; typedef vector<int> vi; const int INF = 1e9; const int MX = 5e5 + 23; const int MOD = 1e9+7; const int MAX_N = 1e6; const int MAX_N2 = 1e5; const int TWO_MOD_INV = 500000004; const int M = 998244353; void solve() { int n,s; cin >> s >> n; map<int, vector<pair<int,int>>>ma; for(int i=0; i<n; ++i) { int val, weight, am; cin >> val >> weight >> am; ma[weight].push_back({val, am}); } vector<vector<long long>>dp(ma.size()+1, vector<long long>(s+1, INT32_MIN)); dp[0][0]=0; int pos=1; ll ans=0; for(auto &[w, items]: ma) { sort(items.begin(), items.end(), greater<pair<int,int>>()); for(int i=0; i<=s; ++i) { dp[pos][s]=dp[pos-1][s]; int cnt=0, num=0, us=0; ll profit=0; while(cnt<items.size() && w*(num+1)<=i) { ++num; profit+=items[cnt].first; if(dp[pos-1][i-w*num]!=INT32_MIN) dp[pos][i]=max(dp[pos][i], dp[pos-1][i-w*num]+profit); ++us; if(items[cnt].second==us) { ++cnt; us=0; } } ans=max(ans, dp[pos][i]); } ++pos; } cout << ans << endl; } int main() { //freopen("feast.in","r",stdin); //freopen("feast.out","w",stdout); int t=1; while(t--) solve(); return 0; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:29:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |     for(auto &[w, items]: ma) {
      |               ^
knapsack.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             while(cnt<items.size() && w*(num+1)<=i) {
      |                   ~~~^~~~~~~~~~~~~
#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...