# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964952 | Acanikolic | 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>
//#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1000000 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
bool check(int A,int B,int T,vector<int>X,vector<int>Y,vector<pair<int,int>>W,vector<pair<int,int>>S,int mid) {
vector<bool>vis(T,false);
priority_queue<int>pq;
int ptr = -1;
for(int i = 0; i < T; i++) {
if(pq.empty() && ptr + 1 < A && X[ptr + 1] > W[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(X[ptr + 1]);
}
ptr += 1;
}
if(mid == 3 && i == 1) {
//cout << "debug:" << X[ptr + 1] << " " << W[i].F << " " << W[i].S << endl;
}
if(pq.empty()) continue;
vis[W[i].S] = true;
pq.pop();
}
if(mid == 3) {
//for(int i = 0; i < T; i++) if(vis[i]) cout << "dbg:::" << i << endl;
//cout << endl;
}
while(pq.size()) pq.pop();
ptr = -1;
for(int i = 0; i < T; i++) {
if(vis[S[i].S]) continue;
if(pq.empty() && ptr + 1 < B && Y[ptr + 1] > S[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(Y[ptr + 1]);
}
ptr += 1;
}
if(pq.empty()) continue;
vis[S[i].S] = true;
pq.pop();
}
bool ok = true;
for(int i = 0; i < T; i++) if(!vis[i]) ok = false;
if(mid == 3) {
// for(int i = 0; i < T; i++) if(vis[i]) cout << "dbg:::" << i << endl;
}
if(ok) return true;
while(pq.size()) pq.pop();
for(int i = 0; i < T; i++) vis[i] = false;
ptr = -1;
for(int i = 0; i < T; i++) {
if(pq.empty() && ptr + 1 < B && Y[ptr + 1] > S[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(Y[ptr + 1]);
}
ptr += 1;
}
if(pq.empty()) continue;
vis[S[i].S] = true;
pq.pop();
}
while(pq.size()) pq.pop();
ptr = -1;
for(int i = 0; i < T; i++) {
if(vis[W[i].S]) continue;
if(pq.empty() && ptr + 1 < A && X[ptr + 1] > W[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(X[ptr + 1]);
}
ptr += 1;
}
if(pq.empty()) continue;
vis[W[i].S] = true;
pq.pop();
}
ok = true;
for(int i = 0; i < T; i++) if(!vis[i]) ok = false;
return ok;
}
int putaway(int A,int B,int T,vector<int>X,vector<int>Y,vector<int>W,vector<int>S) {
vector<pair<int,int>>w(T);
vector<pair<int,int>>s(T);
for(int i = 0; i < T; i++) {
w[i] = {W[i],i};
s[i] = {S[i],i};
}
sort(X.begin(),X.end());
sort(Y.begin(),Y.end());
sort(w.begin(),w.end());
sort(s.begin(),s.end());
reverse(X.begin(),X.end());
reverse(Y.begin(),Y.end());
reverse(w.begin(),w.end());
reverse(s.begin(),s.end());
int l = 1, r = max(A,B),ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(check(A,B,T,X,Y,w,s,mid)) {
ans = mid;
r = mid - 1;
}else {
l = mid + 1;
}
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
vector<int>w(t),s(t);
for(int i = 0; i < t; i++) cin >> w[i] >> s[i];
int a;
cin >> a;
vector<int>x(a);
for(int i = 0; i < a; i++) cin >> x[i];
int b;
cin >> b;
vector<int>y(b);
for(int i = 0; i < b; i++) cin >> y[i];
cout << putaway(a,b,t,x,y,w,s);
return 0;
}