Submission #1172336

#TimeUsernameProblemLanguageResultExecution timeMemory
1172336baqqon_Knapsack (NOI18_knapsack)C++20
0 / 100
141 ms49756 KiB
/**

  III     U   U  N   N  DDDD   EEEEE  RRRR   SSSS  TTTTT  AAAAA  N   N  DDDD      I  TTTTT     N   N   OOO   W   W
   I      U   U  NN  N  D   D  E      R   R  S       T    A   A  NN  N  D   D     I    T       NN  N  O   O  W   W
   I      U   U  N N N  D   D  EEEE   RRRR   SSSS    T    AAAAA  N N N  D   D     I    T       N N N  O   O  W W W
   I      U   U  N  NN  D   D  E      R  R      S    T    A   A  N  NN  D   D     I    T       N  NN  O   O  WW WW
  III     UUUUU  N   N  DDDD   EEEEE  R   R  SSSS    T    A   A  N   N  DDDD      I    T       N   N   OOO   W   W

**/

#include <bits/stdc++.h>
using namespace std;

#define ent '\n'
#define F first
#define S second
#define in insert                                                            
#define no "NO\n"                                                            
#define yes "YES\n"                                                         
#define pb push_back                                                        
#define sz(w) w.size()                                                           
#define int long long                                                       
#define all(w) w.begin(), w.end()                                           
#define BakTR ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int MOD = 998244353, N = 1e3 + 7 , inf = 1e9 + 7, INF = 2e18, LOG = 20 , mod = 1e6 + 7 ;

int dp[101][2001] ;

void accepted() {
    int m , n ;
    cin >> m >> n ;
    vector <int> a , b , k ;
    for(int i = 1; i <= n ; i++) {
        int x , y , z; 
        cin >> x >> y >> z ;
        k.pb(z) ;
        for(int j = 1; j <= z ; j++) {
            if(!binary_search(all(b) , y * j)) {
                if(!binary_search(all(a) , x * j)) {
                    b.pb(y * j) ;
                    a.pb(x * j) ;
                }
            }
        }
    }
    if(n == 1) {
        int s = m / b[1] ;
        if(s >= k[1]) {
            cout << a[1] * k[1] ;
        }
        else {
            cout << a[1] * s ;
        }
        return ;
    }
    for(int i = 0 ; i < a.size() ; i++) {
        for(int j = 0 ; j <= m ; j++) {
            dp[i][j] = dp[i - 1][j] ;
            if(j >= b[i]) {
                dp[i][j] = max(dp[i - 1][j] , dp[i][j - b[i]] + a[i]) ;
            }
        }
    }
    for(int i = 0 ; i < sz(a) ; i++) {
        cout << a[i] << ' ' ;
    }
    cout << ent ;
    for(int i = 0 ; i < sz(b) ; i++) {
        cout << b[i] << ' ' ;
    }
    cout << ent ;
    for(int i = 0 ; i < sz(a) ; i++) {
        for(int j = 0 ; j <= m ; j++) {
            cout << dp[i][j] << ' ' ;
        }
        cout << ent ;
    }
    cout << dp[n][m - 1] ;
}

signed main() {
    BakTR

    //PLS NeverGiveUp

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int T = 1; 
    //cin >> T;
    while (T--) {
        accepted();
        cout << ent;
    }
}

/**
baktr
65868073990A98C52AFDB7A48F4E8D26
**/
#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...