제출 #523503

#제출 시각아이디문제언어결과실행 시간메모리
523503aminKnapsack (NOI18_knapsack)C++14
73 / 100
10 ms1580 KiB
#include <bits/stdc++.h> using namespace std; long long a[1000]; long w[5000],va[5000],t[5000]; long long dp[5000],d[5000]; int main() { long n; long m; cin>>m; cin>>n; vector<pair<long long,long long >>v[5000]; for(long i=0;i<n;i++) { cin>>va[i]>>w[i]>>t[i]; v[w[i]].push_back({-va[i],t[i]}); } for(long i=0;i<=m;i++) { sort(v[i].begin(),v[i].end()); } for(long i=0;i<=m;i++) { for(long y=0 ;y<v[i].size();y++) { v[i][y].first*=-1; //cout<<v[i][y].first; } dp[i]=-1; d[i]=-1; } dp[0]=0; d[0]=0; long long x=0; long long sum=0; for(long i=0;i<=m;i++) { for(long y=0;y<=m;y++) { dp[y]=d[y]; } if(v[i].size()>0) for(long y=0;y<=m;y++) { if(dp[y]!=-1) { x=0; long long b=0; sum=v[i][b].second; for(long u=i;u+y<=m;u+=i) { x+=v[i][b].first; d[y+u]=max(d[y+u],dp[y]+x); sum--; if(sum<=0) { b++; if(b>=v[i].size()) break; sum=v[i][b].second; } } } } } long long ans=0; for(long i=0;i<=m;i++) { ans=max(ans,d[i]); } cout<<ans; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:26:20: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(long y=0 ;y<v[i].size();y++)
      |                   ~^~~~~~~~~~~~
knapsack.cpp:68:25: 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]
   68 |                     if(b>=v[i].size())
      |                        ~^~~~~~~~~~~~~
#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...