This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 1e6 + 5;
int t,n,a[N],v[N],w[N],k[N],s,dp[N];
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>s>>n;
vector <pii> vec;
vec.pb({0, 0});
for (int i = 1; i <= n; i++) {
cin>>v[i]>>w[i]>>k[i];
for (int j = 0; j <= 30; j++) {
if (k[i] >= (1<<j)) {
int x = (1<<j);
k[i] -= x;
if (x * w[i] <= s)
vec.pb({x * v[i], x * w[i]});
}
}
if (k[i] && w[i] * k[i] <= s) vec.pb({k[i] * v[i], k[i] * w[i]});
}
int ans = 0;
for (int i = 1; i < vec.size(); i++) {
for (int j = s; j >= vec[i].s; j--) {
dp[j] = max(dp[j], dp[j - vec[i].s] + vec[i].f);
ans = max(ans, dp[j]);
}
}
cout<<ans<<"\n";
}
Compilation message (stderr)
knapsack.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main() {
| ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:29:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 1; i < vec.size(); 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... |