This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |