Submission #1248647

#TimeUsernameProblemLanguageResultExecution timeMemory
1248647marchell_hiiKnapsack (NOI18_knapsack)C++20
73 / 100
1093 ms2632 KiB
/*
 ███╗   ███╗ █████╗ ██████╗ ███████╗    ██████╗ ██╗   ██╗       ███╗   ███╗ █████╗ ██████╗  ██████╗██╗  ██╗███████╗██╗     ██╗           ██╗  ██╗██╗██╗
 ████╗ ████║██╔══██╗██╔══██╗██╔════╝    ██╔══██╗╚██╗ ██╔╝██╗    ████╗ ████║██╔══██╗██╔══██╗██╔════╝██║  ██║██╔════╝██║     ██║           ██║  ██║██║██║
 ██╔████╔██║███████║██║  ██║█████╗      ██████╔╝ ╚████╔╝ ╚═╝    ██╔████╔██║███████║██████╔╝██║     ███████║█████╗  ██║     ██║           ███████║██║██║
 ██║╚██╔╝██║██╔══██║██║  ██║██╔══╝      ██╔══██╗  ╚██╔╝  ██╗    ██║╚██╔╝██║██╔══██║██╔══██╗██║     ██╔══██║██╔══╝  ██║     ██║           ██╔══██║██║██║
 ██║ ╚═╝ ██║██║  ██║██████╔╝███████╗    ██████╔╝   ██║   ╚═╝    ██║ ╚═╝ ██║██║  ██║██║  ██║╚██████╗██║  ██║███████╗███████╗███████╗█████╗██║  ██║██║██║
 ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝ ╚══════╝    ╚═════╝    ╚═╝          ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝╚════╝╚═╝  ╚═╝╚═╝╚═╝
*/
/*
 ඞ
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣤⣤⣤⣄⡀
 ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠉⠉⠉⠉⠉⠻⢿⣿⣷⡄
 ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀      ⢻⣿⣿⡄
 ⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⠀   ⣠⣾⣿⣿⣿⠿⠿⠿⢿⣿⣿⣄
 ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀    ⣿⣿⣯⠁⠀⠀⠀⠀⠀  ⠙⢿⣷⡄
 ⠀⠀⣀⣤⣴⣶⣶⣿⡟⠀⠀⠀   ⣿⣿⣿            ⣿⣷
 ⠀⢰⣿⡟⠋⠉⣹⣿⡇⠀⠀⠀   ⣿⣿⣿⣷⣦⣀⣀⣀⣀⣀⣀⣀⣿⣿
  ⢸⣿⡇   ⣿⣿⡇⠀⠀     ⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  ⣸⣿⡇   ⣿⣿⡇⠀⠀⠀⠀    ⠉⠉⠉⠉⠉⠉⠉⠉⠉⡿⢻⡇
 ⠀⣿⣿    ⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀       ⢸⣿⡇
 ⠀⣿⣿⠀   ⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀      ⢸⣿⡇
 ⠀⣿⣿⠀⠀  ⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀      ⢸⣿⡇
 ⠀⢿⣿   ⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀         ⣿⡇
 ⠀⠸⣿⣦⡀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀       ⣿⣿
 ⠀⠀⠛⢿⣿⣿⣿⣿⡇    ⠀⣠⣿⣿⣿⣿⣄       ⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⣽⣿⡆     ⢸⣿⡇
 ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀   ⣸⣿⠇
 ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿ ⠀⠈⠻⣿⣿⣿⣿⡿⠏
 ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁
*/
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<pll, pll>
#define pdd pair<double, double>
#define pu push_back
#define po pop_back
#define fi first
#define se second
#define fifi fi.fi
#define fise fi.se
#define sefi se.fi
#define sese se.se
#define cekcek cout<<'c'<<'e'<<'k'<<endl
using namespace std;

ll M, N, v[100005], w[100005], k[100005], dp[2][2005], ans;

int main(){
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin >> M >> N;
for(ll i = 1; i <= N; i++) cin >> v[i] >> w[i] >> k[i];
for(ll i = 1; i <= N; i++){
    for(ll j = 0; j <= M; j++){
        for(ll l = 0; l * w[i] <= j && l <= k[i]; l++){
            dp[i % 2][j] = max(dp[i % 2][j], dp[1 - i % 2][j - l * w[i]] + l * v[i]);
        }
    }
}
for(ll i = 1; i <= M; i++) ans = max(ans, dp[N % 2][i]);
cout << ans << endl;
}
#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...