# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587106 | FatihSolak | Robots (IOI13_robots) | C++17 | 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>
#define N 1000005
using namespace std;
vector<int> x,y;
vector<pair<int,int>> toys;
int a,b,t;
int cnt[N];
bool ck(int x){
if(b == 1){
int cnt = 0;
for(int i = 0;i<t;i++){
cnt++;
long long val = (long long)cnt[i] * x;
while(val && cnt){
val--;
cnt--;
}
}
return cnt == 0;
}
multiset<int> rem;
for(int i = 0;i<t;i++){
rem.insert(toys[i].second);
long long val = (long long)cnt[i] * x;
while(val && rem.size()){
val--;
rem.erase(prev(rem.end()));
}
}
for(int i = b-1;i>=0;i--){
int val = x;
while(val && rem.size() && *rem.begin() < y[i]){
val--;
rem.erase(prev(rem.lower_bound(y[i])));
}
}
return rem.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
x.push_back(1);
y.push_back(1);
for(int i = 0;i<A;i++){
x.push_back(X[i]);
}
for(int i = 0;i<B;i++){
y.push_back(Y[i]);
}
for(int i = 0;i<T;i++){
toys.push_back({W[i],S[i]});
}
a = A+1;
b = B+1;
t = T;
sort(x.begin(),x.end());
sort(y.begin(),y.end());
sort(toys.begin(),toys.end());
for(auto u:toys){
if(u.first >= x.back() && u.second >= y.back()){
return -1;
}
}
int pt = 0;
for(auto u:x){
while(pt < t && toys[pt].first < u){
pt++;
}
if(pt)
cnt[pt-1]++;
}
int l = 1,r = t;
while(l < r){
int m = (l+r)/2;
if(ck(m)){
r = m;
}
else l = m+1;
}
return l;
}