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;
using ll = long long;
using ld = long double;
const ll maxn = 2003;
const ll mod = 1e9 + 7;
struct TPair
{
ll v , w , k;
};
ll dp[maxn][maxn] , inf = 1e18;
TPair a[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("","r",stdin);
//freopen("","w",stdout);
int s , n;
cin>>s>>n;
for(int i = 1 ; i <= n ; ++i)
cin>>a[i].v>>a[i].w>>a[i].k;
ll kq = 0;
for(int i = 1 ; i <= s ; ++i) dp[0][i] = -inf;
dp[0][0] = 0;
for(int i = 1 ; i <= n ; ++i)
{
for(int j = 1 ; j <= s ; ++j)
{
dp[i][j] = -inf;
for(int h = 0 ; h <= a[i].k ; ++h)
{
ll so1 = a[i].w * h , so2 = a[i].v * h;
if(so1 > j) break;
dp[i][j] = max(dp[i][j] , dp[i - 1][j - so1] + so2);
kq = max(kq , dp[i][j]);
}
}
}
cout<<kq;
}
# | 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... |