This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Nếu thế giới có 8 tỷ người yêu em, anh là một trong số họ
//Nếu thế giới có 1 người yêu em, thì anh chính là người đó
//Nếu thế giới không còn ai yêu em, thì có nghĩa là anh đã chết </3
//dyk19b1
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define BIT(mask,i) ((mask >> i) & 1ll )
#define endl '\n'
#define all(x) x.begin(),x.end()
#define ii pair <int,int>
using namespace std;
#define read doc()
int doc () {bool minus = false;int result = 0;char ch;ch = getchar();while (true) {if (ch == '-') break;if (ch >= '0' && ch <= '9') break;ch = getchar();}if (ch == '-') minus = true; else result = ch-'0';while (true) {ch = getchar();if (ch < '0' || ch > '9') break;result = result*10 + (ch - '0');}if (minus)return -result;else return result;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> T rand(T l, T h) { return uniform_int_distribution <T> (l, h) (rng); }
template <class T> T rand(T h) { return uniform_int_distribution <T> (0, h - 1) (rng); }
template<class X, class Y>bool minimize(X &x, const Y &y) {if (x > y) {x = y;return true;} else return false;}
template<class X, class Y>bool maximize(X &x, const Y &y) {if (x < y) {x = y;return true;} else return false;}
const long long oo = 1e18;
const int N = 1e6+5;
const int MOD = 1e9+7;
int s,n;
struct typ
{
int v,w,k;
} a[N];
vector <ii> b;
// int dp[50010][2001];
int dp[2002];
void TnKh()
{
cin >> s >> n;
FOR(i,1,n)
{
int v,w,k;
cin >> v >> w >> k;
a[i] = {v,w,k};
}
FOR(i,1,n)
{
auto [v,w,k] = a[i];
int j = 0;
for(;(1 << (j+1))-1 <= k;j++)
{
int kc = (1 << j);
if (w * kc > s) break;
b.push_back(make_pair(v*kc,w*kc));
// weight[w *kc] = max(weight[kc*w],v*kc);
}
if (k-(1 << (j))+1) b.push_back(make_pair(v*(k-(1 << (j))+1),w * (k-(1 << (j))+1) ));
}
// dp.assign(b.size()+1);
// dp.resize(s);
n = b.size()-1;
// for(auto [v,w]:b) cout << v << " " << w << endl;
FOR(i,0,n)
{
FORD(j,s,1)
{
// cout << i << " " << j << endl;
if (j >= b[i].se)
{
// cout << i << " " << j << endl;
maximize(dp[j],dp[j-b[i].se] + b[i].fi);
}
}
FORD(j,1,s) maximize(dp[j],dp[j-1]);
}
cout<< dp[s];
return;
}
#define TASK "task"
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);
int Dyk19b1 = 1;
// cin >> Dyk19b1;
while (Dyk19b1--) TnKh();
return 0;
}
Compilation message (stderr)
knapsack.cpp: In function 'void TnKh()':
knapsack.cpp:45:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | auto [v,w,k] = a[i];
| ^
# | 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... |