제출 #1188459

#제출 시각아이디문제언어결과실행 시간메모리
1188459teokakabadzeKnapsack (NOI18_knapsack)C++20
100 / 100
63 ms14660 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define int long long #define pii pair<int, int> using namespace std; const int N = 5e5 + 5, M = 1e9 + 7; int T, n, s, dp[2003]; vector<pii> d[N], b; main() { std::ios::sync_with_stdio(0); cin.tie(0); int i; cin >> s >> n; for(i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; d[w].pb({v, k}); } for(i = 1; i <= s; i++) { sort(d[i].begin(), d[i].end()); reverse(d[i].begin(), d[i].end()); int w = 0, sv = 0; for(auto [v, k] : d[i]) { while(w < s && k) { w += i, sv += v; b.pb({w, sv}); k--; } } for(int j = s; j >= 0; j--) { for(auto [w, v] : b) if(j >= w) dp[j] = max(dp[j], dp[j - w] + v); } b.clear(); } cout << dp[s] << '\n'; }

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

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