제출 #650289

#제출 시각아이디문제언어결과실행 시간메모리
650289ono_de206Knapsack (NOI18_knapsack)C++14
100 / 100
126 ms4904 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int mxn=1e5+10; const int mxm=2010; vector<pair<int,int>> lol[mxm]; int dp[2][mxm]; signed main(){ // freopen("feast.in","r",stdin); // freopen("feast.out","w",stdout); int s,n; cin>>s>>n; for(int i=0; i<n; i++){ int v,w,k; cin>>v>>w>>k; lol[w].push_back({v,k}); } int st=1; for(int i=1; i<=s; i++){ if(lol[i].empty()) continue; st^=1; sort(lol[i].rbegin(),lol[i].rend()); for(int j=1; j<=s; j++) dp[st][j]=dp[st^1][j]; for(int j=1; j<=s; j++){ int idx=0; int now=1; int hhe=0; int cur=0; while(now*i<=j && hhe<lol[i].size()){ cur+=lol[i][hhe].first; if(dp[st^1][j-(now*i)]+cur>dp[st][j]){ dp[st][j]=dp[st^1][j-(now*i)]+cur; } now++; idx++; if(idx==lol[i][hhe].second){ hhe++; idx=0; } } } } int ans=0; for(int i=1; i<=s; i++) ans=max(ans,dp[st][i]); cout<<ans<<'\n'; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:34: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]
   34 |    while(now*i<=j && hhe<lol[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...