제출 #846941

#제출 시각아이디문제언어결과실행 시간메모리
846941batsukh2006Knapsack (NOI18_knapsack)C++17
73 / 100
50 ms5660 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> #include<numeric> 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!=b) return a.first>b.first; else return a.second>b.second; } void solve(){ int s,n; cin>>s>>n; vector<pair<int, int> > v[s+1]; for(int i=0; i<n; i++){ int a,b,c; cin>>a>>b>>c; v[b].push_back(make_pair(a,c)); } vector<pair<int, int> > f; for(int i=1; i<=s; i++){ sort(v[i].begin(),v[i].end(),scnd); for(int j=0,k=0; j<=s/i; j++){ if(v[i].size()<=k) break; if(v[i][k].second==0) k++; if(v[i][k].second>0) f.push_back(make_pair(i,v[i][k].first)),v[i][k].second--; } } 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("feast.in", "r", stdin); // freopen("feast.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; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:40:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   40 |             if(v[i].size()<=k) break;
      |                ~~~~~~~~~~~^~~
knapsack.cpp:46:19: 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...