Submission #1043764

#TimeUsernameProblemLanguageResultExecution timeMemory
1043764vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cerr << #x << " => " << x << endl #define all(x) x.begin(),x.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int s,n;cin>>s>>n; pair<int,pii> p[n]; for(int i=0;i<n;i++) cin>>p[i].se.fi>>p[i].fi>>p[i].se.se; sort(p,p+n,greater<pair<int,pii>>()); vector<pii> a; int now=s,cnt=0; for(int i=0;i<n;i++) { if(p[i].fi!=now) now=p[i].fi,cnt=0; while(cnt!=s/now && p[i].se.se!=0) { a.pb({p[i].fi,p[i].se.fi}); p[i].se.se--; cnt++; } } ll dp[2][s+1]; memset(dp,0,sizeof(dp)); for(int i=0;i<a.size();i++) { for(int j=0;j<=s;j++) { dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j]); if(j+a[i].fi<=s) dp[i%2][j+a[i].fi]=max(dp[i%2][j+a[i].fi],dp[(i+1)%2][j]+a[i].se); } // for(int j=0;j<=s;j++) cout<<dp[i][j]<<' ';cout<<'\n'; } cout<<dp[(n-1)%2][s]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=0;i<a.size();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...