제출 #1024518

#제출 시각아이디문제언어결과실행 시간메모리
1024518giorgi_pkhaladzeKnapsack (NOI18_knapsack)C++17
100 / 100
89 ms15528 KiB
#include <bits/stdc++.h> #define int long long #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define ff first #define ss second #define gcd __gcd using namespace std; int n,m,s,k,i,j,ans,dp[200005],a[200005],b[200005],c[200005],cnt[200005]; vector<pii> v[200005],nivtebi; signed main() { cin>>s>>n; for(i=1; i<=n; i++){ cin>>a[i]>>b[i]>>c[i]; cnt[b[i]]+=c[i]; v[b[i]].pb({a[i],c[i]}); } nivtebi.pb({0, 0}); for(k=1; k<=s; k++){ sort(v[k].rbegin(),v[k].rend()); int raod=min(s/k,cnt[k]); for(i=0; i<v[k].size(); i++){ if(v[k][i].ss<=raod) { for (int j=1; j<=v[k][i].ss; j++) { nivtebi.pb({k, v[k][i].ff}); } raod-=v[k][i].ss; } else { for (int j=1; j<=raod; j++) { nivtebi.pb({k, v[k][i].ff}); } raod=0; break; } } } for(k=1; k<nivtebi.size(); k++){ for(i=s; i>=0; i--){ if (i>=nivtebi[k].ff) dp[i]=max(dp[i-nivtebi[k].ff]+nivtebi[k].ss,dp[i]); ans=max(ans, dp[i]); } } cout<<ans; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:23: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]
   23 |         for(i=0; i<v[k].size(); i++){
      |                  ~^~~~~~~~~~~~
knapsack.cpp:38:15: 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]
   38 |     for(k=1; k<nivtebi.size(); k++){
      |              ~^~~~~~~~~~~~~~~
#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...