Submission #1339247

#TimeUsernameProblemLanguageResultExecution timeMemory
1339247lha9002Knapsack (NOI18_knapsack)C++20
73 / 100
1096 ms460 KiB
#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ii pair<int,int>
#define li pair<ll , int>
using namespace std;
const int N = 1e6;
const int N1 = 2e5;
const int Mod = 1e9 + 7;
int n;
ll f[N + 3];
ll s;
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define NAME "test"
//    freopen(NAME".in", "r" , stdin);
//    freopen(NAME".out" , "w" , stdout);
    if(fopen(NAME".inp" , "r")){
        freopen(NAME".inp", "r" , stdin);
        freopen(NAME".out" , "w" , stdout);
    }
    cin >> s >> n;
    FOR(i , 1 , n){
        ll val,wei,sl;
        cin >> val >> wei >> sl;
        FORD(j , s , 1)
            FOR(k , 1 , sl){
                if(wei * k > j) break;
                f[j] = max(f[j] , f[j - wei * k] + val * k);
            }
    }
    cout << f[s];
    return 0;
}
//}‍‍
//            LHA - Fail - gpt - try again
//            👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨
//
//            ╔███╗     ██╗  ██╗  █████╗
//            ║███║     ██║  ██║ ██╔══██╗
//            ║███║     ███████║ ███████║
//            ║███║     ██╔══██║ ██╔══██║
//            ║█████║   ██║  ██║ ██║  ██║
//            ╚═════╝   ╚═╝  ╚═╝ ╚═╝  ╚═╝
//
//                        A N H
//            👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨👨‍❤️‍👨
//            <<<===✦ DP core magic ✦===>>>

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(NAME".inp", "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(NAME".out" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...