Submission #844627

#TimeUsernameProblemLanguageResultExecution timeMemory
844627batsukh2006Knapsack (NOI18_knapsack)C++11
0 / 100
0 ms344 KiB
#include<iostream> #include<stdio.h> #include<math.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<string.h> #include<utility> #include<set> #include<cmath> #include<queue> #include<deque> #include<functional> #include<stack> #include<limits.h> #include<iomanip> #include<unordered_map> using namespace std; #define MOD 1000000007 #define int long long #define endl '\n' bool scnd(pair<int, int> a, pair<int, int> b){ if(a.first!=b.first) return(a.first<b.first); else return(a.second>b.second); } void solve(){ int s,n; cin>>s>>n; vector<pair<int, int> > p[s+1]; for(int i=0; i<n; i++){ int v,w,k; cin>>v>>w>>k; p[w].push_back(make_pair(v,k)); } vector<pair<int, int> > f; for(int i=1; i<=s; i++){ sort(p[i].begin(),p[i].end(),scnd); for(int j=0,k=0; j<s/i; j++){ if(j>=p[i].size()) break; if(p[i][k].second>0) f.push_back(make_pair(i,p[i][k].first)),p[i][k].second--; else k++,j--; } } vector<int> dp(s+1); for(int i=0; i<f.size(); i++){ for(int j=s; j>=f[i].first; j--){ dp[j]=max(dp[j],dp[j-f[i].first]+f[i].second); } } cout<<dp[s]; } signed main(){ // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); cout<<endl; } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:40:8: 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]
   40 |    if(j>=p[i].size()) break;
      |       ~^~~~~~~~~~~~~
knapsack.cpp:46:16: 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]
   46 |  for(int i=0; i<f.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...