Submission #915639

#TimeUsernameProblemLanguageResultExecution timeMemory
915639AmrKnapsack (NOI18_knapsack)C++14
37 / 100
1033 ms2912 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
ll mx = -1e18;
ll dp[N];
void solve()
{
    for(int i = 0; i < N; i++) dp[i]  = -1e18;
    dp[0] = 0;
    ll n , k; cin >> n >> k;
    swap(n,k);
    ll a[n+1][3];
    for(int i = 1; i<= n ;i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
    ll mx = -1e18;
    for(int i = 1; i <= n;i++)
    {
        for(int j = k; j>= 0; j--)
        {
            for(int l = 1; l <= a[i][2]; l++)
            {
                if(j-l*a[i][1]<0) continue;
                if(dp[j-l*a[i][1]]!=-1e18) dp[j] = max(dp[j],dp[j-l*a[i][1]]+l*a[i][0]);
            }
        }
    }
    for(int i = 0; i <= k; i++) mx = max(mx,dp[i]);
    cout << mx << endl;
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    //cin >> TT;
    while(TT--)
        solve();

    return 0;
}
#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...