This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,fma")
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
//#define int long long
inline int read() {
// opt = 0;
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
//if (ch == ' ') opt = 1;
return x * f;
}
constexpr int sz = 1e5 + 5;
constexpr long long inf = (long long)1E18 + 7;
int n, s;
struct ou{
int v, w, k;
} a[sz];
long long dp[2005];
signed main(){
s = read(), n = read();
for(register int i = 1; i <= n; ++i){
a[i].v = read(), a[i].w = read(), a[i].k = read();
a[i].k = min(a[i].k, s / a[i].w);
}
for(register int i = 1; i <= 2001; ++i){
dp[i] = -inf;
}
for(register int i = 1; i <= n; ++i){
for(register int ki = 1; ki <= a[i].k; ++ki)
for(register int j = s; j >= a[i].w; --j){
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
long long ans = *max_element(dp, dp+s+1);
cout << ans << '\n';
}
Compilation message (stderr)
knapsack.cpp: In function 'int main()':
knapsack.cpp:40:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
40 | for(register int i = 1; i <= n; ++i){
| ^
knapsack.cpp:45:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
45 | for(register int i = 1; i <= 2001; ++i){
| ^
knapsack.cpp:49:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
49 | for(register int i = 1; i <= n; ++i){
| ^
knapsack.cpp:50:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
50 | for(register int ki = 1; ki <= a[i].k; ++ki)
| ^~
knapsack.cpp:51:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
51 | for(register int j = s; j >= a[i].w; --j){
| ^
# | 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... |