Submission #753867

#TimeUsernameProblemLanguageResultExecution timeMemory
753867ivazivaKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100010 #define MAXM 2010 //sutra ujutru kucam ovo long long s; long long n; vector<pair<long long,long long>> vec; long long dp[MAXM]; int main() { ios_base::sync_with_stdio(false); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>s>>n; for (long long i=1;i<=n;i++) { long long x; long long y; long long z; long long br=min(s/y,z); for (long long j=1;j<=br;j++) vec.push_back({y,x}); } long long siz=vec.size(); sort(vec.begin(),vec.end()); long long ans=0; for (long long i=0;i<siz;i++) { long long ww=vec[i].first; long long vv=vec[i].second; for (long long j=ww;j<=s;j++) { dp[j-ww]=max(dp[j-ww],dp[j]+vv); ans=max(ans,dp[j-ww]); } } cout<<ans<<endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:27: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |         long long br=min(s/y,z);
      |                          ~^~
knapsack.cpp:26:19: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |         long long z;
      |                   ^
#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...