Submission #1307072

#TimeUsernameProblemLanguageResultExecution timeMemory
1307072ng.annhaatKnapsack (NOI18_knapsack)C++20
100 / 100
38 ms3024 KiB
/*
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░  ░░░░░░░░   ░░░░░   ░           ░   ░░░░   ░░░░░     ░░░░░░        ░░░░
▒▒▒▒▒▒  ▒  ▒▒▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒   ▒▒▒   ▒▒▒▒   ▒▒▒   ▒▒▒▒   ▒▒
▒▒▒▒▒  ▒▒   ▒▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒   ▒   ▒▒▒▒▒▒▒▒   ▒   ▒▒▒▒   ▒▒
▓▓▓▓   ▓▓▓   ▓▓▓▓   ▓▓▓▓▓   ▓▓▓▓▓   ▓▓▓▓▓          ▓   ▓▓▓▓▓▓▓▓   ▓  ▓   ▓▓▓▓▓▓
▓▓▓       ▓   ▓▓▓   ▓▓▓▓▓   ▓▓▓▓▓   ▓▓▓▓▓   ▓▓▓▓   ▓   ▓▓▓▓▓▓▓▓   ▓   ▓▓   ▓▓▓▓
▓▓   ▓▓▓▓▓▓▓   ▓▓   ▓▓▓▓▓   ▓▓▓▓▓   ▓▓▓▓▓   ▓▓▓▓   ▓▓▓   ▓▓▓▓▓   ▓▓   ▓▓▓▓   ▓▓
█   █████████   ███      ████████   █████   ████   █████     ██████   ██████
███████████████████████████████████████████████████████████████████████████████

         ▄▄▄      ███▄    █  ███▄    █   ██░ ██  ▄▄▄      ▄▄▄     ▄▄▄█████▓
        ▒████▄    ██ ▀█   █  ██ ▀█   █ ▒▓██░ ██ ▒████▄   ▒████▄   ▓  ██▒ ▓▒
        ▒██  ▀█▄ ▓██  ▀█ ██▒▓██  ▀█ ██▒░▒██▀▀██ ▒██  ▀█▄ ▒██  ▀█▄ ▒ ▓██░ ▒░
        ░██▄▄▄▄██▓██▒  ▐▌██▒▓██▒  ▐▌██▒ ░▓█ ░██ ░██▄▄▄▄██░██▄▄▄▄██░ ▓██▓ ░
         ▓█   ▓██▒██░   ▓██░▒██░   ▓██░ ░▓█▒░██▓ ▓█   ▓██ ▓█   ▓██  ▒██▒ ░
         ▒▒   ▓▒█░ ▒░   ▒ ▒ ░ ▒░   ▒ ▒   ▒ ░░▒░▒ ▒▒   ▓▒█ ▒▒   ▓▒█  ▒ ░░
          ░   ▒▒ ░ ░░   ░ ▒░░ ░░   ░ ▒░  ▒ ░▒░ ░  ░   ▒▒   ░   ▒▒     ░
          ░   ▒     ░   ░ ░    ░   ░ ░   ░  ░░ ░  ░   ▒    ░   ▒    ░ ░
              ░           ░          ░   ░  ░  ░      ░        ░


*/
//#include <bits/BaoMinhTranc++.h>
#include <bits/stdc++.h>
#define int int64_t
//#define ll int64_t
#define ld long double
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define ALLr(x) x.rbegin(),x.rend()
#define upgrade ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define name "youreagoodmanarthur"
using namespace std;
const int Max=1<<20;
const int N=2e3+3;
const int INF=1e18;
const int MOD=998244353;
const int MOD2=1e9+8;
const int base=26;
const int LOG=32;
template<class X,class Y>
    bool minimize(X& x,const Y& y)
    {
        if(x>y){
            x=y;
            return 1;
        }return 0;
    }
template<class X,class Y>
    bool maximize(X& x,const Y& y)
    {
        if(x<y){
            x=y;
            return 1;
        }return 0;
    }
int s,n;
int dp[N];
vector<ii> a[N];
void add(int v,int w)
{
    for(int j=s;j>=w;j--)maximize(dp[j],dp[j-w]+v);
}
void solve()
{
    cin>>s>>n;
    for(int i=1;i<=n;i++){
        int v,w,k;cin>>v>>w>>k;
        a[w].push_back({v,k});
    }
    for(int i=1;i<=s;i++)if(!a[i].empty()){
        sort(ALLr(a[i]));
        int take=s/i;
        int it=1,cur=0;
        while(take--){
            if(it>a[i][cur].se){
                cur++;it=1;
                if(cur==a[i].size())break;
            }
            add(a[i][cur].fi,i);
            it++;
        }
    }
    cout<<*max_element(dp,dp+s+1);
}
void prepare()
{

}
signed main()
{
    upgrade
    if(fopen(name".INP","r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }
    prepare();
    int test=1;
//    cin>>test;
    while(test--)solve();
    return 0;
}
/*

                                                                                                       ░▓▓
                                                                 ░▒▒▒         ░▒▒▒▒▒▒░░░               ░▓▓
▓▒        ▒▓▓▓▓▓▓▓▓▓▓▓▓▒                  ░▓▓▓▓▓▓▓▓▓▓▓▒░       ▒▓▓▒      ▒▒▒▒░   ░░░░▒░▒▒▒▒▒▒          ░▓▓    ░░▒▒▒▒▒░░
▒▓▓▒   ▒▓▓░            ░▓▓▒           ░▓▓▓▒            ░▒▓▓░░▓▓▒      ▒▒▒  ▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒░       ░▓▓▓▒▒▒▒▒▒▒▒▒▒▓▒▒░
   ▓▓▓▓▒                 ░▓▓▒       ▒▓▓▒                 ░▓▓▓░      ░▒░        ░▒▒▒▒▒▒▒▒  ▒▒▒░ ▒▒▒     ░▓▓
                          ░▓▓░     ▓▓▓                                                 ░▒▒▒ ▒▒▒ ░▒▒    ▒▓▒
                           ▒▓▒    ▓▓▓                                      ░░            ▒▒░ ▒▒▒ ▒▒░   ▓▓▓
                           ░▓▒   ░▓▓▓                                  ░▒  ▒▒░           ▒▒░ ▒▒░ ▒▒▒   ▓▓▓░
                           ░▓▒   ░▓▓▓▒                                 ▒▒▒ ░▒▒▒░       ░▒▒░ ░▒▒ ▒▒▒    ▓▓▓▒
                           ▒▓▒     ▓▓▓░                      ░      ▒▒░  ▒▒▒   ▒▒▒▒▒▒▒▒░  ▒▒▒▒▒▒▒▒     ░▓▓▓
                          ░▓▓▒      ▒▓▓▓▒                 ░▓▓▓▓▒     ░▒▒   ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░ ▒▒▒░        ░▓▓▓
                           ░▒         ░▓▓▓▓▓▓▒░       ▒▓▓▓▓▓▒▓▓▒        ▒▒▒▒▒▒▒░    ░▒▒▒▒▒▒▒░             ▓▓▓▓▒▒       ▒▓▓▓▓
                                           ░░▓▓▓▓▓▓▓▓▒░░     ▒▓▒                 ░▒▒▒▒░                       ░▒▓▓▓▓▓▓▓▓▒░
                                                             ▒▓▓░                  ▒▒░
                            ▓▒                               ▒▓▓░                  ▒▒▒░
                            ▓▓▒                             ░▓▓▒                  ░▒▒▒▒
                             ▓▓▓░                          ▒▓▓▓                    ░▒▒▒
                               ░▓▓▓▓░                   ░▓▓▓▒
                                   ░▓▓▓▓▓▒▒░░░  ░░░▒▒▓▓▓▓░
                                         ░▒▒▒▒▒▒▒▒░
*/

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         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...