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 "robots.h"
using namespace std;
#define all(v) v.begin(), v.end()
const int NMAX = 1e6 + 5;
int A, B, T, X[NMAX], Y[NMAX], W[NMAX], S[NMAX];
int go(int A, int B, int T, int X[], int Y[], int W[], int S[], int m){
vector<pair<int, int>> v;
priority_queue<int> pq;
for(int i = 0; i < T; i++) v.emplace_back(W[i], S[i]);
sort(all(v));
int ix = 0;
for(int i = 0; i < A; i++){
while(ix < T && v[ix].first < X[i]) pq.emplace(v[ix++].second);
for(int j = 0; j < m; j++){
if(pq.size()) pq.pop();
else break;
}
}
while(ix < T) pq.emplace(v[ix++].second);
for(int i = B - 1; i >= 0; i--){
for(int j = 0; j < m; j++){
if(pq.size() && Y[i] > pq.top()) pq.pop();
else break;
}
}
return pq.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
int l = 1, r = T + 1, m;
sort(X, X + A);
sort(Y, Y + B);
while(l < r){
m = (l + r) / 2;
if(go(A, B, T, X, Y, W, S, m)) r = m;
else l = m + 1;
}
return l == T + 1 ? -1 : r;
}
/*
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> A >> B >> T;
for(int i = 0; i < A; i++) cin >> X[i];
for(int i = 0; i < B; i++) cin >> Y[i];
for(int i = 0; i < T; i++) cin >> W[i] >> S[i];
cout << putaway(A, B, T, X, Y, W, S);
return 0;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |