Submission #478888

#TimeUsernameProblemLanguageResultExecution timeMemory
478888NightRageKnapsack (NOI18_knapsack)C++14
100 / 100
323 ms36728 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector <ll> #define vii vector <pair<ll,ll>> #define ii pair<ll,ll> #define loop(n) for(ll i=0;i<n;i++) #define loopj(n) for(ll j=0;j<n;j++) #define pb push_back #define ll_SIZE 60 const ll MAXDIV = 2000000000000LL; ll mod=1e9+7; const ll N=5e5+5; ll n,m,k; ll a,b; ll dp[2005][2005]; vector<pair<ll,ll>> mp[2005]; ll solve(ll idx,ll we){ if(idx>m) return 0; ll &ret=dp[idx][we]; if(~ret)return ret; ret=solve(idx+1,we); ll tt=0; for (ll i = 0; i < mp[idx].size() && we+idx<=m; ++i) { ll tmp= mp[idx][i].second; while(we+idx<=m && tmp>0){ tt+=mp[idx][i].first; we+=idx; ret=max(ret,tt+solve(idx+1,we)); tmp--; } } return ret; } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); // cout.tie(NULL); ll tt=1; // cin >>tt; while(tt--){ cin >>m >> n; memset(dp,-1,sizeof(dp)); loop(n){ ll v,w,k; cin >> v >>w >>k; mp[w].emplace_back(v,k); } for (ll i = 1; i <= m; ++i) { sort(mp[i].begin(),mp[i].end()); reverse(mp[i].begin(),mp[i].end()); } cout <<solve(0,0) <<endl; } }

Compilation message (stderr)

knapsack.cpp: In function 'long long int solve(long long int, long long int)':
knapsack.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (ll i = 0; i < mp[idx].size() && we+idx<=m; ++i) {
      |                    ~~^~~~~~~~~~~~~~~~
#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...