제출 #716833

#제출 시각아이디문제언어결과실행 시간메모리
716833amine_arouaKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms468 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(ll i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(ll i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define ub upper_bound
#define lb lower_bound

const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;

ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)

// HERE IS THE SOLUTION

int main()
{
    cin.tie(0);
    cout.tie(0);
    boost;
    ll s , n;
    cin>>s>>n;
    vl val(n) , weight(n) , k(n);
    forr(i, 1 , n)
    {
        cin>>val[i]>>weight[i]>>k[i];
    }
    vector<vl> dp(s+1 , vl(n+1 , 0));
    forr(i ,1 , n)
    {
        forr(w , 1 , s)
        {
            ll curk = k[i] , y = weight[i] , v = val[i];
            ll x = 0;
            while(w - x*y>=0&&x<=curk)
            {
                dp[w][i] = max(dp[w][i] , dp[w - x*y][i-1]+x*v);
                x++;
            }
        }
    }
    cout<<dp[s][n]<<nl;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...