# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309690 | amunduzbaev | 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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const int N1=5e4+5;
int t,a,b,a1[N1],b1[N1],w[N],s[N];
int used[N1];
bool check(int m){
for(int i=0;i<t;i++){
int l=0,r=a-1;
while(l<r){
int mid=(l+r)/2;
if(al[mid]>=w[i])
r=mid;
else
l=mid+1;
}
while(used[l]==m&&l<a)
l++;
if(l==a&&used[l]==m)
return 0;
used[l]++;
}
return 1;
}
int putaway(int A, int B, int T, int A1[], int B1[], int W[], int S[]) {
t=T,a=A,b=B;
for(int i=0;i<t;i++){
w[i]=W[i];
s[i]=S[i];
}
for(int i=0;i<a;i++) a1[i]=A1[i];
for(int i=0;i<b;i++) b1[i]=B1[i];
sort(a1,a1+a);
sort(b1,b1+b);
for(int i=0;i<t;i++){
if(a&&b){
if(w[i]>=a1[a-1]&&s[i]>=b1[b-1]) return -1;
}else if(a){
if(w[i]>=a1[a-1]) return -1;
}else{
if(s[i]>=b1[b-1]) return -1;
}
}
if(t==2){
if(a>0&&b>0){
return (a1[0]>w[0]&&b1[0]>s[1]||a1[0]>w[1]&&b1[0]>s[0]) ? 1 : 2 ;
}
if(a>0){
return (a1[0]>w[0]&&a1[1]>w[1]||a1[1]>w[0]&&a1[0]>w[1]) ? 1 : 2 ;
}
if(b>0){
return (b1[0]>s[0]&&b1[1]>s[1]||b1[1]>s[0]&&b1[0]>s[1]) ? 1 : 2 ;
}
}
int l=1,r=t;
while(l<r){
int m=(l+r)/2;
if(check(m))
r=m;
else
l=m+1;
}
return l;
}