# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
401714 | bonopo | 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 <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define el "\n"
#define f first
#define s second
typedef long long ll;
const ll MM=1e5+5, MOD=1e9+7;
int A, B, T, x[MM], y[MM], u[MM];
priority_queue<pair<int,int>> pq;
struct toy {
int wt, sz, idx;
} t[10*MM];
bool cmpw(toy a, toy b) {
return a.wt<b.wt;
}
bool cmps(toy a, toy b) {
return a.sz<b.sz;
}
bool check(int sec) {
memset(u, 0, sizeof(u)); int ptr=1, hv=0;
// take highest weight you can
sort(t+1, t+T+1, cmpw);
for(int i=1; i<=A; ++i) {
while(ptr<=T&&t[ptr].wt<x[i]) {
pq.push({t[ptr].sz, ptr++}); }
int cnt=sec;
while(!pq.empty()&&cnt) {
pair<int,int> e=pq.top(); pq.pop();
if(!u[t[e.s].idx]) {
u[t[e.s].idx]=1; ++hv; --cnt; }
}
}
sort(t+1, t+T+1, cmps);
while(!pq.empty()) pq.pop(); ptr=1;
// take highest size you can
for(int i=1; i<=B; ++i) {
while(ptr<=T&&t[ptr].sz<y[i]) {
pq.push({t[ptr].wt, ptr++}); }
int cnt=sec;
while(!pq.empty()&&cnt) {
pair<int,int> e=pq.top(); pq.pop();
if(!u[t[e.s].idx]) {
u[t[e.s].idx]=1; ++hv; --cnt; }
}
} return hv==T;
}
int putaway(int _a, int _b, int _t, int X[], int Y[], int W[], int S[]) {
A=_a; B=_b; T=_t;
for(int i=0; i<A; ++i) x[i+1]=X[i];
for(int i=0; i<B; ++i) y[i+1]=Y[i];
for(int i=0; i<T; ++i) t[i+1].wt=W[i];
for(int i=0; i<T; ++i) t[i+1].sz=S[i];
for(int i=0; i<T; ++i) t[i+1].idx=i+1;
if(A>0) sort(x+1, x+A+1);
if(B>0) sort(y+1, y+B+1);
int lo=1, hi=T, mid, ans=-1;
while(lo<=hi) {
mid=(lo+hi)/2;
if(check(mid)) hi=mid-1, ans=mid;
else lo=mid+1; }
return ans;
}