Submission #203989

#TimeUsernameProblemLanguageResultExecution timeMemory
203989mdn2002Kitchen (BOI19_kitchen)C++14
0 / 100
115 ms376 KiB
#include<bits/stdc++.h> using namespace std; int n,m,k,a[305],b[305],c[305],d[303],mn=1e9; vector<int>v; int ckk() { memset(c,0,sizeof c); memset(d,0,sizeof d); vector<int>vv=v; for(int i=0;i<n;i++) { for(int j=0;j<vv.size();j++) { if(vv[j]==0)continue; if(d[i]==k)break; d[i]++; vv[j]--; c[i]++; } if(d[i]!=k)return 0; } for(int i=0;i<n;i++) { for(int j=0;j<vv.size();j++) { if(vv[j]==0)continue; if(c[i]==a[i])break; int old=c[i]; c[i]+=min(a[i]-c[i],vv[j]); vv[j]-=min(a[i]-old,vv[j]); } if(c[i]!=a[i])return 0; } int sum=0; for(int i=0;i<vv.size();i++)sum+=vv[i]; mn=min(mn,sum); return 1; } bool ck(int val) { int l=0,r=0,sum=0,mx=0; while(l<m) { if(r<m&&sum<=val) { sum+=b[r]; v.push_back(b[r]); r++; } else { sum-=b[l]; v.erase(v.begin()); l++; } if(sum<=val)mx=max(mx,ckk()); } return mx; } int main() { cin>>n>>m>>k; for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<m;i++)cin>>b[i]; sort(a,a+n); sort(b,b+m); int l=0,r=100000,mid; while(l<r) { cout<<l<<' '<<r<<endl; mid=(l+r)/2; int c=ck(mid); if(c)r=mid; else l=mid+1; } if(mn!=1e9)cout<<mn<<endl; else cout<<"Impossible"<<endl; }

Compilation message (stderr)

kitchen.cpp: In function 'int ckk()':
kitchen.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv.size();j++)
                     ~^~~~~~~~~~
kitchen.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv.size();j++)
                     ~^~~~~~~~~~
kitchen.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vv.size();i++)sum+=vv[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...