This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
const ll modulo = 1e4;
//#define int ll
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.in","r",stdin);
// freopen("haybales.out","w",stdout);
int W,n;
cin >> W >> n;
if(n==1){
int v,w,k;
cin >> v >> w >> k;
assert(n==1);
cout << v*min(k,W/w);
return 0;
}
vector<pair<ll,ll>> items(n);
for (int i = 0; i < n; i++) {
cin >> items[i].second >> items[i].first;
int k;cin>>k;
k=min(1999,k);
for (int j = 1; j < k; j++) {
items.emplace_back(items[i].first,items[i].second);
}
}
vector<ll> DP(W+1);
for(auto&item:items){
for (int i = W; i >= item.first; i--) {
DP[i] = max(DP[i],DP[i-item.first]+item.second);
}
}
cout << DP[W];
}
# | 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... |