제출 #938876

#제출 시각아이디문제언어결과실행 시간메모리
938876andrewpKnapsack (NOI18_knapsack)C++14
17 / 100
1 ms348 KiB
//Dedicated to my love, ivaziva
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define here cerr<<"---------------------------------\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
#define ll long long
#define ld long double
#define llinf 100000000000000000LL
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define sz(s) (ll)(s.size())
#define ios ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
#define mod 1000000007
using namespace std;
/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
ll add(ll x,ll y){
    if(x+y>=mod) return x+y-mod;
    return x+y;
}
ll sub(ll x,ll y){
    if(x-y<0) return x-y+mod;
    return x-y;
}
ll mul(ll x,ll y){
    ll res=(x*y)%mod;
    if(res<0) res+=mod;
    return res;
}
ll pw(ll x,ll y){
	ll ret=1,bs=x;
	for(;y;y>>=1){
		if(y&1) ret=mul(ret,bs);
		bs=mul(bs,bs);
	}
	return ret%mod;
}*/
#define maxn 2005
ll n,s;
ll v[maxn],w[maxn];
vector<pll> c[maxn];
ll dp[maxn];
void tc(){
    cin >> s >> n;
    for(ll i = 1;i<=n;i++){
        ll vu,wu,k;
        cin >> vu >> wu >> k;
        c[wu].pb({vu,k});
    }
    ll id=1;
    for(ll i = 1;i<=s;i++){
        if(sz(c[i])==0) continue;
        sort(c[i].rbegin(),c[i].rend());
        ll mx=s/i;
        for(ll j = 0;j<sz(c[i]);j++){
            if(!mx) break;
            mx--;
            for(ll k = s;k>=i;k--) dp[k]=max(dp[k],dp[k-i]+c[i][j].fi);
        }
    }
    ll ans=0;
    for(ll i = 0;i<=s;i++) ans=max(ans,dp[i]);
    cout<<ans<<endl;
}
int main(){
	ios
    int t; t = 1;
//    cin >> t;
    while(t--){
        tc();
    }
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'void tc()':
knapsack.cpp:60:8: warning: unused variable 'id' [-Wunused-variable]
   60 |     ll id=1;
      |        ^~
#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...