Submission #1157611

#TimeUsernameProblemLanguageResultExecution timeMemory
1157611arkanefuryKnapsack (NOI18_knapsack)C++20
37 / 100
1095 ms1096 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define lb lower_bound
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define FOR1(x, n) for(int j = x; j <= n; j ++)
#define FOR(x, n, m, d) for(int x = n; x <= m; x += d)
#define FORR(x, n, m, d) for(int x = n; x >= m; x -= d)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
const int N =  2e5+5;
int a[N], b[N], pref[N], c[N];
int n,m,k,sum=0,x,y, ans, r, cnt, l, mod = 1e9+7;
string s, str;
void solve(){
    cin >> m >> n;
    FOR(i,1,n,1){
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    ans = 0;
    FOR(i, 1, n, 1){
        FOR(j, 1, m, 1){
            dp[i][j] = dp[i-1][j];
            if( b[i] <= j ){
                k = c[i];
                while(k){
                if(j >= b[i]*k)dp[i][j] = max(dp[i][j], dp[i-1][j-b[i]*k] + a[i] * k);
                k --;
                }
            }
            ans=max(ans, dp[i][j]);
        }
    }
    cout << ans;
    
}
signed main(){
    nikita
    int tt = 1;
    if(!tt)cin >> tt;
    FOR(i, 1, tt, 1)solve();
}
#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...