# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1170297 | yamiza_zinno | Knapsack (NOI18_knapsack) | C++20 | 594 ms | 460 KiB |
/*
/\_/\
(= ._.)
/ >0 \>1
*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#define fi first
#define se second
#define el cout<<"\n"
#define rtn return
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define fz(i,a,n,z) for(int i=a;i<n;i+=z)
#define rep(i,a,n,z) for(int i=a;i>n;i-=z)
#define onii_chan ios_base::sync_with_stdio(false);
#define baka cin.tie(0);
#define hentai cout.tie(0);
#define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
template<typename... T>
void in(T&... args) { ((cin >> args), ...); }
template<typename... T>
void print(T&&... args) { ((cout << args << " "), ...); }
template<typename... T>
void println(T&&... args) { ((cout << args << " "), ...); cout << '\n'; }
template<typename... T>
void printl(T&&... args) { ((cout << args << "\n"), ...); }
template <typename T>
bool minimize(T& a, const T& b) {
return b < a ? (a = b, true) : false;
}
template <typename T>
bool maximize(T& a, const T& b) {
return a < b ? (a = b, true) : false;
}
const int MAXN = 1e6+5;
const int mod =1e9+7;
inline void add(int &a,int b){
a+=b;
if(a >= mod) a-=mod;
if(a < 0) a+=mod;
}
///---------------------------------------------------------------
/// End the template, take a sip of Coke before reading the code ඞඞඞඞඞ
int a[MAXN];
long long dp[MAXN];
signed main(){
onii_chan;
baka;hentai;
file("TEST");
int s,n;in(s,n);
f1(i,n){
int v,w,k;
in(v,w,k);
vector<int> block;
for(int j=1;k > 0;j*=2){
int x=min(j,k);
block.push_back(x);
k-=x;
}
for(int x : block){
for(int j=s;j>=1ll*x*w;j--) maximize(dp[j],dp[j-x*w]+x*v);
}
}
print(dp[s]);
}
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢟⣵⣿⣿⣿⣷⣦⣝⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⠩⠑⣺⣿⣿⣦⣝⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⣁⠟⠛⠛⠻⠿⣿⣿⣦⡈⠩⣤⣤⣽⣏⣋⡉⠉⣠⣥⣴⣾⠿⠙⠋⠻⠿⣷⣧⡙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠱⠋⠉⠁⠀⠀⠀⠀⠀⣀⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣏⣀⡀⠀⠀⠀⠀⠁⠘⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢋⠆⣐⣀⠔⠀⠀⢀⣀⣴⣾⣿⣿⣿⠟⠋⣈⣽⣿⣿⣿⣿⣿⣿⣿⣿⢿⣦⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣬⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣣⣿⣿⣿⡟⠁⢀⣴⣿⡟⢹⣿⣿⣉⠄⣠⣼⡟⡟⠛⣶⡄⢻⣿⣿⣿⣿⣧⠩⣿⣦⡀⠀⠀⠈⣿⣿⣿⣿⣿⣯⡻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣼⢯⣿⣿⡏⢀⣴⣿⣿⡟⢀⣾⢻⡿⠋⣼⣿⣟⢰⡇⢰⣿⣷⠈⢿⣿⢻⣿⣿⣆⠸⣿⣷⡀⠀⠀⢿⣿⣿⣿⣿⣟⣿⣜⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⣼⣻⣿⣿⠋⢰⣾⣿⢿⡿⢁⡾⠁⠞⠀⡸⣿⣿⡇⣹⣿⣿⣿⣿⣆⠸⣿⠄⢻⣿⣿⣆⠹⢿⣿⡄⠀⢸⠿⣿⣿⣿⣿⣞⣿⡍⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠯⡾⠽⣽⣿⠇⢠⣿⠿⢁⣾⠗⡼⠃⠈⠀⢰⠣⣿⣿⠈⣿⣿⡿⣿⣿⣿⠀⠘⣶⠈⣿⣿⣿⣆⢸⣿⣷⠀⠈⠀⣿⣿⣿⣿⣿⣿⣿⡜⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⡿⡵⣽⢫⣻⣿⡏⢀⣾⠋⢂⣾⠏⢀⡏⠀⠀⠀⡏⢰⣿⡿⢠⣿⣿⡇⢙⣿⣿⠀⠀⢻⡇⢸⣿⣿⣿⡟⣿⡿⡆⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⡜⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⡿⢋⣸⣹⢃⡾⣽⡿⠁⣾⡏⡂⣾⠏⠀⢸⠀⠀⠀⢠⠃⢸⣿⡇⢸⣿⣿⡇⠀⣿⣿⠀⠀⠀⢇⠈⣿⣿⣿⡇⣿⡇⢹⡀⠀⢹⣿⣿⣿⢿⣿⣿⣿⣿⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣫⣥⣶⣿⠷⢎⢿⢇⣿⠁⢸⡟⠈⣼⠟⠀⠀⠈⠀⠀⠀⢸⠀⣿⣿⡇⢸⣿⡟⡇⠈⣿⣿⠀⠀⠀⠘⠀⢹⣿⣿⡇⢻⡇⣸⡅⠀⢸⣿⣿⣿⡞⣿⣿⣿⣿⡇⢻⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⠂⡈⠠⣸⡏⠀⣿⠁⢤⡏⠀⠀⠀⠇⠀⠀⠀⢸⠀⣿⣿⣧⣼⣿⡿⢷⠀⣿⡟⠀⠀⠀⠀⠀⠸⣿⣿⡇⢸⣿⣿⡇⠀⢸⣿⣿⣿⣷⢻⣿⣿⣿⣷⠘⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⡆⣿⠁⢠⡏⠀⡜⠀⠀⢀⡄⠀⠀⢠⡆⢸⠀⢸⣿⡏⢸⣿⡇⢸⡆⣿⠃⠀⠀⠀⠀⠀⠀⣿⣿⡇⢸⣿⢸⣿⠀⢸⣿⣿⣿⣿⢸⣿⣿⣿⢿⡀⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⡇⠀⢀⢱⡟⠀⣸⠁⢠⠃⠀⣰⣿⣇⠀⢠⣿⣇⢸⠀⠀⣿⡃⢸⣿⣧⠘⠷⠉⠀⠀⠀⡀⠀⠀⠀⢷⣿⡇⢸⣿⠠⣿⠀⢸⣿⣿⣿⣿⢸⣿⣿⣇⢸⠀⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⠇⠀⠸⢸⡇⠀⣿⠀⠀⠀⣰⣿⣿⣿⠀⣾⣿⣿⡘⠀⠀⣿⡇⢸⣿⣿⠀⢧⠀⠀⢀⣾⣿⡀⠀⠀⠀⢻⡇⢸⣿⠀⣿⡀⢸⣿⣿⣿⣿⠘⣿⣿⣿⢻⠃⢿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⠀⠀⢠⢸⡇⠀⣿⠀⠇⠀⠿⠿⢿⣿⡀⣿⣿⣿⣄⠇⠀⢸⡇⠈⣿⣿⡆⠀⠀⠀⡾⠿⢿⣗⡀⠀⠀⠀⠃⣼⣿⠀⣿⡇⠈⣿⣿⣿⣿⠀⣿⣿⡏⠘⣆⢸⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⡟⡀⠀⠀⢻⣇⠀⡏⠀⠀⣾⠟⠛⠓⠒⠦⠘⠭⣭⣇⣠⠀⡄⠇⠀⣿⠚⣧⠀⠠⠤⠐⠛⠻⠿⠿⠄⠀⠀⠀⣿⡿⢀⣿⡇⠀⣿⣿⣿⣇⠀⣿⣿⡇⢸⣿⢸⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⢇⡇⠀⠀⠸⣿⠀⠃⠀⠀⠁⠀⢀⠀⠀⠀⠀⠀⣾⣿⡄⠀⢀⠘⠀⢸⡄⠘⡄⠠⠂⠀⠀⠀⠀⠀⠀⠀⠀⠰⣿⡇⢸⣿⣷⠀⣿⡟⢻⡇⠀⢹⣿⡇⢸⣿⡾⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⡿⠴⠃⠀⠀⠀⣿⠀⢰⡄⠀⠀⣾⡏⠀⠀⠀⠀⠀⢺⣿⣧⠀⢸⡄⠀⢸⣧⠀⠱⠀⠆⠀⠀⠀⠀⠀⢰⣤⠀⠀⠀⡇⢸⣿⡏⠀⣿⣇⢸⡇⠀⢸⣿⡇⢸⣿⡇⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⢸⣿⡀⠘⠀⠀⣾⣿⡷⠀⠀⠀⢠⡄⢸⣿⣿⣆⠀⣷⠀⠸⠿⡆⠀⠄⣠⡤⠀⠀⣤⠀⢠⣿⡇⠀⠈⣧⣼⣿⡇⢠⣿⡿⣿⡇⠀⢸⣿⡇⢸⠛⡇⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⡀⡀⠀⠀⠀⢸⢻⡇⠀⡆⠀⣿⣿⣷⡀⢤⣴⡆⣠⣿⣿⣿⣿⡆⢻⣧⣾⣷⣶⣶⣶⣦⡀⠀⠠⠄⢀⣾⣿⠃⡎⢺⠀⣿⣿⡇⢸⣿⠀⣿⠇⠀⣾⣿⡇⠘⠀⢁⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣀⠀⠀⠀⠀⠘⠸⣿⡀⢹⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣹⣿⣦⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣷⣿⡿⣿⠀⡇⠈⢰⠇⣿⠀⣾⣿⠀⣿⠀⠀⣿⣿⠇⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⡄⠀⢿⣷⠈⢧⠈⠻⣿⣿⠿⠿⠿⠿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠐⣼⠀⣿⠀⣿⣿⠀⣿⠀⠀⣿⣿⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⡇⠀⢠⠀⠀⠀⠀⠘⠿⠷⠄⠀⠈⣉⡁⠀⠐⠒⠒⠛⠛⠠⠤⠤⠤⠤⠐⠛⠋⠉⢉⣉⡉⢽⡟⠛⠛⠿⢟⠀⠀⠀⢿⠀⡇⠀⢿⡟⠀⣿⠀⠀⣿⣿⢀⣲⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⡇⣷⣾⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⢿⣿⣿⣿⣷⣶⣶⣶⣶⣶⣶⣶⣦⣤⣤⣤⣤⣤⣤⣤⣤⣤⡄⠀⠀⢰⡏⠀⡇⠀⢸⡇⠀⣿⠀⢀⡿⢿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣷⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠈⡿⣟⣿⣿⣾⣿⣿⣿⣏⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⢸⡇⠀⡇⠀⢸⡇⠀⢻⠀⢸⡇⢸⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⡟⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⢀⣼⠃⠀⡇⠀⢸⣇⡆⠸⠀⢸⣇⣸⡟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣇⢿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⢹⠀⠀⡇⠀⣼⢸⡇⣠⡀⠈⣿⠙⣇⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣇⠘⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⢠⠀⠀⠀⠈⠙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠁⠀⠀⠀⣀⣄⡀⣺⠀⠀⡇⠀⠏⣾⣟⠀⠀⠀⣿⠀⡏⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣄⠈⠋⠀⠀⠀⠀⠀⠀⠀⠀⢸⣷⣦⣀⠀⠀⠀⠀⠉⠻⣿⣿⣿⣿⠿⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠈⠙⠃⡇⣿⠀⠀⡇⠀⢰⣿⣿⡤⠀⠀⢿⡶⣷⠺⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⡷⠀⡄⠀⠀⠀⠀⠆⠀⠀⢸⣿⣿⣿⣿⣷⣶⣶⣾⠗⡠⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠇⠀⢾⣿⣿⣿⣅⠀⢸⣿⣿⣀⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⢟⣼⢰⠃⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⢰⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⢠⢰⠀⡇⠀⢸⠀⠀⣾⣿⣿⣿⣿⠀⢸⣿⣸⡏⢻⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⠏⣾⢇⠇⢀⠀⢠⡀⠀⠀⣾⠀⠈⣿⣿⣿⣿⣿⣿⠇⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⡟⠃⠀⣀⣴⣿⣞⢧⡇⠀⠸⠀⡴⣿⣿⣿⣿⣿⡇⢸⡿⡟⡇⣸⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣟⢹⠏⡘⢀⣾⢀⣾⡇⠀⠄⣿⣧⠀⣿⣿⡿⢟⣛⣍⣾⣿⣿⡆⠀⠀⢀⣀⣠⣤⣾⡿⠛⠉⣀⣤⣾⣿⣿⣿⣿⣷⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⡇⢸⡇⡇⡇⢹⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⡚⢀⣇⣾⡏⣸⣿⣧⠀⢧⣿⣿⡆⠛⣋⢸⣿⣯⣿⣿⣿⣿⣿⣆⠀⠀⣿⠟⠉⢁⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⢸⢹⣿⣿⣿⣿⠇⡸⣹⡇⣇⣼⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⡿⠀⢰⣿⣏⠁⣉⣥⡄⢸⠚⣿⡏⣇⣸⣿⡞⣿⣿⣿⣿⣿⣿⣿⡟⢀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠈⡆⣌⣉⣛⠻⠠⢡⣿⡇⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⡟⡀⠀⠈⣿⣿⡀⢻⢿⡇⢸⠀⣿⢇⢸⠉⣿⣷⡸⣿⣿⣿⣿⣿⠟⣰⣿⡷⣄⡀⢠⣤⣤⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⡀⠀⡇⠀⠘⡘⣿⣿⠃⢀⣶⣦⠁⣈⣛⣻⠟⠛⠻⠻⠿⣿⣿
// ⣿⣿⡿⣱⣿⡆⣶⡹⠇⣷⡐⣦⣌⠘⠀⡏⢸⡎⠀⣿⣿⣷⠙⣿⣿⣿⡏⣸⣿⣿⣗⣼⠗⣾⣿⣿⡇⢽⣿⣿⣿⣿⣿⣿⠟⢋⣴⣷⣄⠁⣀⠀⠣⠙⢁⣴⣿⣿⡟⣰⣿⣿⣿⣿⣿⣿⣷⣦⡈⢻
// ⣿⡿⢁⣿⣿⣆⢹⣿⣬⣿⣷⡹⣿⡄⠘⢀⣶⣭⡀⣿⣿⣿⣧⣈⠿⡿⠀⠈⢿⣿⣿⣿⢧⣿⣿⠟⠁⡜⣿⣿⡿⡟⣋⣔⣴⣿⣿⣿⣏⢷⣄⣿⣶⣌⡹⣿⣿⣿⣱⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⡅
// ⡿⠁⣸⣿⣿⣿⣇⢿⣿⣿⣿⣿⣿⣷⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣾⣷⠘⣿⣿⣿⣸⣯⣥⣴⣾⣿⣿⣽⣶⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⠹⣿⣿⣿⣿⣿⣿⣿⠟⣡⣾⣿⣿⣷
컴파일 시 표준 에러 (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... |