제출 #1215189

#제출 시각아이디문제언어결과실행 시간메모리
1215189free_de_la_zenithKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms2636 KiB
/**
 *    author:  MINHTPC
 *
**/
#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin() , a.end()
#define FOR(i ,a , b) for(int i = a ; i <= b ; ++i)
#define bit(mask,i) ((mask>>i)&1)
#define name "task"
#define lo lower_bound
#define up upper_bound
#define count_bit1(x) __builtin_popcountll(x)
#define count_bit01(x) __builtin_clzll(x)
#define count_bit10(x) __builtin_ctzll(x)

using namespace std;
const int N=3e6+5;
long long dp[N],a[N],b[N],K[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int s,n;
    cin >> s >> n;
    for(int i=1;i<=n;i++)  cin >> a[i] >> b[i] >> K[i];
//    long long x=accumulate(a+1,a+n+1,0LL);
    for(int i=1;i<=n;i++) {
        ll k=K[i];
        ll rs=1;
        while(k) {
            ll cnt=min(rs,k);
            ll w=b[i]*cnt;
            ll v=a[i]*cnt;
            for(int j=s;j>=w;j--)  dp[j]=max(dp[j],dp[j-w]+v);
            k-=cnt;
            rs<<=1;
        }
    }
    cout << dp[s] << '\n';
}

#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...