| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1322656 | trandinhnhat | Knapsack (NOI18_knapsack) | C++20 | 1096 ms | 2360 KiB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define ch char
#define task ""
#define pb push_back
#define ii pair<ll,ll>
#define iii pair <ll, ii>
#define fi first
#define se second
using namespace std;
template<class X, class Y>
bool maximize(X &x, const Y &y) { return (x < y) ? (x = y, true) : false; }
template<class X, class Y>
bool minimize(X &x, const Y &y) { return (x > y) ? (x = y, true) : false; }
const ll mod = 1e9 + 7;
const ll N = 5005;
const ll inf = LLONG_MAX;
const ll SHIFT = 1e6;
ll a[N], w[N], v[N], dp[N][N];
ll n, s;
void sub1();
void sub2();
void sub3();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
if (fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
cin >> s >> n;
for (ll i = 1; i <= n; i++) {
cin >> v[i] >> w[i] >> a[i];
}
for (ll i = 1; i <= n; i++) {
for (ll j = s; j >= w[i]; j--) {
for (ll k = 0; k <= a[i]; k++) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j - k * w[i] >= 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - k * w[i]] + k * v[i]);
}
}
}
}
cout << dp[n][s];
return 0;
}
/*Set the pace, set the goal, maintain your streak by solving problem everyday*/
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⣠⡀⠀⠀⠀⠀⠀⣀⣴⠞⠀⠀⠀⠀⠀⠀ ⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⡼⣿⠀⠀⠀⣀⠴⠋⢡⠎⠀⠀⣀⡠⠴⠒⢉⠟⠁⠀⠀⠀ ⣀⣠⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⡄⠀⠀⠀⢠⠎⠀⡇⢀⡠⠚⠁⠀⢀⡯⠤⠚⠋⠁⠀⢀⡴⢃⣀⠤⠖⠛⠉⣠⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡜⢧⠀⠀⣰⠋⠀⢠⡧⠋⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠰⠞⠋⠉⠀⠀⠀⢀⡜⠁⣀⣀⣀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣰⠁⢸⡀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠋⠉⠉⠉⠉⠉⠉⢉⡭⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡏⠀⠀⠿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠖⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢸⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⣋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⣀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠙⣟⠒⠤⡧⠀⠀⠀⠀⠀⠀⠀⠐⢦⠀⠀⠀⠀⣄⠀⠀⠀⠀⢶⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠈⢦⠀⠀⠀⠀⠀⢀⣤⣴⣶⠿⢿⣷⣦⡀⠀⠘⣷⡄⠀⠀⠀⢳⣄⠀⠀⠀⠀⠰⡄⠀⠀⠀⠀⠀⠐⢶⠲⠤⣤⣌⡑⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠈⢳⡀⣠⣴⡾⠟⠉⠁⠀⠀⠈⢸⣿⣿⣦⡀⠈⢿⣶⣄⠀⠈⢻⣿⣶⣄⠀⠀⢹⣄⠀⠀⠀⠀⠀⠈⠳⡀⠀⠀⠈⠉⠃⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⡿⢟⢁⡀⠀⢀⣀⡤⠶⠒⠛⣿⣿⣿⣿⣦⣌⢿⣿⣿⣦⡀⢿⣿⣿⣿⣦⣄⣿⣷⣄⠀⠀⢷⠤⣀⠹⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⣼⡁⢰⣸⣷⠞⠋⠀⠀⠀⠀⠤⢿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣷⣿⣿⣿⠿⣿⣿⣿⣿⣷⣄⠸⡆⠈⠙⠾⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢿⣽⡿⡏⠛⠀⠀⠀⣀⣤⣶⣶⣾⣿⡿⠿⠛⠛⠉⣏⠉⠁⠀⢰⠟⣯⣾⡟⠻⣿⡍⠉⠛⣟⠳⣽⡀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢸⠟⠃⠀⢀⣤⣶⣿⣿⣿⡿⣋⡭⣄⠀⠀⠀⠀⠀⠘⣆⠀⠀⡏⠀⣿⣿⣧⡀⢿⡷⠀⠀⠘⣄⠈⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠈⡇⣀⣶⣾⣿⠿⣫⢿⢟⣵⣾⣟⣻⠀⠀⠀⠀⠀⠀⠹⣶⡀⡇⠀⠈⣿⣇⠇⣾⡷⠀⠀⠀⠘⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠻⣿⣿⡋⠀⠸⠁⠎⣿⣿⣟⡿⠇⠀⠀⠀⠀⠀⠀⠀⠯⢳⡇⠀⠀⠛⠋⣸⣿⠆⠀⠀⠀⢤⣜⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠈⢻⣳⡆⢠⣶⡆⠛⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠀⠀⣀⣀⣽⡋⠀⠀⠀⠀⠘⣏⠛⢧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠘⢿⡇⢰⣿⡗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⡟⡏⢷⠀⠀⠀⠀⣤⡘⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⠁⠰⣿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣇⠃⠈⡆⠀⠀⠀⢹⡙⢿⡀⠀⠀⣀⣀⣠⣤⣤⡄⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢰⠃⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⢹⣄⣀⣀⣼⣷⣶⣾⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⠳⢴⣯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡀⢀⣀⡤⠤⠄⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣏⡠⢤⣴⠄⠀⠀⠀⢀⣠⣤⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣄⠀⠛⢀⣠⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣸⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⣽⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀
⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀
⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷
*/
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
