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 int long long
#define vec vector
#define code signed main()
template<typename _T>
bool chmax(_T &a, const _T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
code
{
int n , m;
cin >> m >> n;
vec<int> dp(m + 1 , 0);
for (int i = 1; i <= n; i++){
int v , w , k;
cin >> v >> w >> k;
for (int x = 1; k > 0; x <<= 1){
int kol = min(k , x);
k -= kol;
int val = v * kol;
int wei = w * kol;
for (int j = m; j >= wei; j--)
chmax(dp[j] , dp[j - wei] + val);
}
}
cout << *max_element(dp.begin() , dp.end()) << "\n";
return 0;
}
# | 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... |