제출 #500292

#제출 시각아이디문제언어결과실행 시간메모리
500292MohamedFaresNebiliKnapsack (NOI18_knapsack)C++14
100 / 100
88 ms38480 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; using vi = vector<ll>; #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound ll s, n; ll v[2 * 100005], w[2 * 100005], k[2 * 100005]; vector<ii> arr[2005]; ll dp[2005][2005]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for(ll l = 0; l < n; l++) { cin >> v[l] >> w[l] >> k[l]; arr[w[l]].pb({v[l], k[l]}); } int last = 0; ll res = 0; for(int l = 1; l <= s; l++) { if(!(int)arr[l].size()) continue; sort(all(arr[l]), greater<ii>()); for(int i = 0; i <= s; i++) { dp[l][i] = dp[last][i]; ll curr = 0, ind = 0, profit = 0; for(int j = 1, k = 0; j <= i; j++, k++) { if(k == arr[l][ind].ss) k = 0, ind++; profit += arr[l][ind].ff; if(j * l > i || ind == (int)arr[l].size()) break; dp[l][i] = max(dp[l][i], dp[last][i - j * l] + profit); } res = max(res, dp[l][i]); } last = l; } cout << res << "\n"; return 0; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:33:24: warning: unused variable 'curr' [-Wunused-variable]
   33 |                     ll curr = 0, ind = 0, profit = 0;
      |                        ^~~~
#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...