제출 #688659

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
6886592023-01-27 23:42:55tcmmichaelb139Knapsack (NOI18_knapsack)C++17
29 / 100
3 ms336 KiB
#include "bits/stdc++.h"
using namespace std;
struct node {
long long v, w, k;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long s, n;
cin >> s >> n;
vector<node> v(n);
for (int i = 0; i < n; i++)
cin >> v[i].v >> v[i].w >> v[i].k;
sort(begin(v), end(v), [](node a, node b) {
if (a.v == b.v) return a.w < b.w;
return a.v > b.v;
});
long long dp[s + 1];
memset(dp, 0, sizeof dp);
long long ans = 0;
for (int i = 0; i < n; i++) {
for (long long j = s; j >= 0; j--) {
for (long long a = min(v[i].k, (s - j) / v[i].w); a >= max(min(v[i].k, (s - j) / v[i].w) - 0, 0ll); a--) {
dp[j + v[i].w * a] = max(dp[j + v[i].w * a], dp[j] + v[i].v * a);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...