Submission #1024516

#TimeUsernameProblemLanguageResultExecution timeMemory
1024516giorgi_pkhaladzeKnapsack (NOI18_knapsack)C++17
49 / 100
6 ms9048 KiB
#include <bits/stdc++.h> #define ll 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; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, 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: 'int' and 'std::vector<std::pair<int, 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...