# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373844 | eulerdesoja | Robots (IOI13_robots) | C++14 | 0 ms | 0 KiB |
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>
#include<fstream>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) int(x.size())
typedef pair<int,int>ii;
typedef vector<int> vi;
bool solve(int p,int a,int b,int t,int x[],int y[],int w[],int s[]){
int id=0;//onde eu parei nos brinquedu
priority_queue<ii,vector<ii>>pq;
for(int i=0;i<a;i++){
for(;id<t;id++){
if(w[id]>=x[i])break;
pq.push({s[id],w[id]});
}
int cnt=0;
while(!pq.empty() && cnt<p){
cnt++;
pq.pop();
}
}
for(;id<t;id++)pq.push({s[id],w[id]});
for(int i=b-1;i>=0;i--){
int cnt=0;
while(!pq.empty() && pq.top().first<y[i] && cnt<p){
cnt++;
pq.pop();
}
}
return pq.empty();
}
int putaway(int A,int B,int T,int X[],int Y[],int W[],int S[]){
int a=A,b=B,t=T;
int x[a],y[b],w[t],s[t];
for(int i=0;i<a;i++)x[i]=X[i];
for(int i=0;i<b;i++)y[i]=Y[i];
for(int i=0;i<t;i++)w[i]=W[i];
for(int i=0;i<t;i++)s[i]=S[i];
sort(x,x+a);
sort(y,y+b);
vector<ii>aux;
for(int i=0;i<t;i++)aux.pb({w[i],s[i]});
sort(aux.begin(),aux.end());
for(int i=0;i<t;i++){
w[i]=aux[i].first;
s[i]=aux[i].second;
}
int l=0,r=t+10;
while(l<r){
int m=(l+r)/2;
if(solve(m,a,b,t,x,y,w,s))r=m;
else l=m+1;
}
return r==t+10?-1:r;
}
/*int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
//setIO("sort");
int a,b,t;
int x[20],y[20],w[20],s[20];
cin>>a>>b>>t;
for(int i=0;i<a;i++)cin>>x[i];
for(int i=0;i<b;i++)cin>>y[i];
for(int i=0;i<t;i++)cin>>w[i];
for(int i=0;i<t;i++)cin>>s[i];
cout<<putaway(a,b,t,x,y,w,s);
return 0;
}*/