# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
418439 | Bill_00 | 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 "robots.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>s[1000005];
bool vis[1000005];
int putaway(int A, int B, int T, int X[], int Y[], int W[], int H[]) {
sort(X,X+A);
sort(Y,Y+B);
for(int i=0;i<T;i++){
if(W[i]>=X[A-1] && H[i]>=Y[B-1]) return -1;
}
for(int i=0;i<A;i++){
for(int j=0;j<T;j++){
if(W[j]<X[i]) s[i].push_back(j);
}
}
for(int i=0;i<B;i++){
for(int j=0;j<T;j++){
if(H[j]<Y[i]) s[i+A].push_back(j);
}
}
int k=0,ans=0;
while(k<T){
for(int i=0;i<=(A+B-1);i++){
while(s[i].size()>0 && vis[s[i].back()]==1) s[i].pop_back();
if(s[i].size()){
vis[s[i].back()]=1;
s[i].pop_back();
k++;
}
}
ans++;
}
return ans;
}
int main(){
int a,b,t,x[1000],y[1000],w[1000],h[1000];
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] >> h[i];
}
cout << putaway(a,b,t,x,y,w,h);
}