# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
993319 | emad234 | 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 "bits/stdc++.h"
#define F first
#define S second
#define ll long long
#define pii pair<int,int>
const int mxN = 5e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
vector<pii>v;
int w[mxN],s[mxN];
int a,b;
bool solve(int m){
priority_queue<int>q;
int i = 0;
for(auto x : v){
if(x.F >= w[i] && i < a){
int t = m;
while(t-- && q.size()) q.pop();
i++;
}
q.push(x.S);
}
for(i; i < a;i++) {
int t = m;
while(t-- && q.size()) q.pop();
}
i = 0;
for(i;i < b;i++){
int t = m;
while(t-- && q.size() && q.top() < s[i]) q.pop();
}
return q.empty();
}
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++) w[i] = X[i];
for(int i = 0;i < B;i++) s[i] = Y[i];
v.clear();
for(int i = 0;i < T;i++) v.push_back({W[i],S[i]});
sort(v.begin(),v.end());
int l = 1,r = T;
int md;
int ans = -1;
while(l < r){
md = (l + r) / 2;
if(solve(md)){
ans = md;
r = md;
}else l = md + 1;
}
return ans;
}