제출 #942489

#제출 시각아이디문제언어결과실행 시간메모리
942489AtabayRajabliKnapsack (NOI18_knapsack)C++17
73 / 100
29 ms8480 KiB
#include <bits/stdc++.h> // author : a1abay #define all(v) v.begin(), v.end() #define GCD(a, b) __gcd(a, b) #define int ll #define LCM(a, b) (a*b / (__gcd(a, b))) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long ll; const int inf = 1e9 + 7; const int inff = (int)1e18 + 7; const int sz = 1e5 + 5; using namespace std; int s, n; int v[sz], w[sz], f[sz], dp[sz]; vector<array<int, 2>> g[sz]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("in.in", "r", stdin); freopen("out.out", "w", stdout); cin >> s >> n; for(int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> f[i]; g[w[i]].push_back({v[i], f[i]}); } for(int i = 1; i <= s; i++) { sort(all(g[i])); int mx = s / i, last = -1; while(!g[i].empty()) { int x = g[i].back()[1], v = g[i].back()[0]; if(mx - x >= 0) { mx -= x; g[i].pop_back(); } else x = mx; for(int j = 1; j <= x; j++) { for(int k = s; k >= i; k--) { dp[k] = max(dp[k - i] + v, dp[k]); } } if(mx == x)break; } } int mx = -1; for(int i = 0; i <= s; i++)mx = max(mx, dp[i]); cout << mx; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:39:25: warning: unused variable 'last' [-Wunused-variable]
   39 |         int mx = s / i, last = -1;
      |                         ^~~~
#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...