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: belgute2
LANG: C++
TASK: cownomics
*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef complex <double> P;
typedef pair<long long, long long> Point;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define X real()
#define Y imag()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MOD1 1000000009
#define sqr(x) sqr((x)*(x))
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef BE_DEBUG
#define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int N = 105;
int s,n;
ll val[N], wei[N], num[N];
ll dp[2005];
ll ans;
int main() {
IOS
cin >> s >> n; // s <= 2000
for(int i = 1; i <= n; i ++) {
cin >> val[i] >> wei[i] >> num[i];
}
for(int i = 1; i <= n; i ++) {
for(int j = s; j >= 0; j --) {
for(int x = 1; x <= num[i]; x ++) {
if(x * wei[i] + j > s) break;
dp[x * wei[i] + j] = max(dp[x * wei[i] + j], dp[j] + val[i] * x);
ans = max(ans, dp[x * wei[i] + j]);
}
}
}
cout << ans;
}
# | 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... |