# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
962947 | serkanrashid | 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;
struct toy
{
int w,s;
toy(){};
toy(int wi, int si)
{
w = wi;
s = si;
}
};
int t;
toy a[1e6];
int a,b,x[5e4],y[5e4];
bool cmp2(toy p1, toy p2)
{
if(p1.s==p2.s) return p1.w>p2.w;
return p1.s<p2.s;
}
bool check(int z)
{
int p = 0;
for(int i = 0; i < a; i++)
{
int br = 0;
while(br<z&&p<t&&k[p].w<=x[i])
{
br++;
p++;
}
}
vector<toy>pom;
for(int i = p; i < t; i++) pom.push_back(k[i]);
sort(pom.begin(),pom.end(),cmp2);
p = 0;
for(int i = 0; i < b; i++)
{
int br = 0;
while(br<z&&p<pom.size()&&k[p].s<=y[i])
{
br++;
p++;
}
}
return p>=pom.size();
}
bool cmp1(toy p1, toy p2)
{
if(p1.w==p2.w) return p1.s>p2.s;
return p1.w<p2.w;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
a = A;
b = B;
for(int i = 0; i < A; i++) x[i] = X[i]-1;
for(int i = 0; i < B; i++) y[i] = Y[i]-1;
t = T;
for(int i = 0; i < T; i++)
{
k[i].w = W[i];
k[i].s = S[i];
}
if(a) sort(x,x+a);
if(b) sort(y,y+b);
for(int i = 0; i < T; i++) if((!a||w[i]>x[a-1])&&(!b||s[i]>y[b-1])) return -1;
sort(a,a+t,cmp1);
int l = 1, r = t;
int mid;
while(l<=r)
{
mid = (l+r)/2;
if(check(mid)) r = mid-1;
else l = mid+1;
}
return l;
}