This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#include"robots.h"
#endif // LOCAL
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 2e5 + 5;
vector<int> query[maxn];
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
sort(X, X + A); sort(Y, Y + B);
int n = A + B;
for(int i = 0; i < T; ++i){
int l = upper_bound(X, X + A, W[i]) - X;
int r = upper_bound(Y, Y + B, S[i]) - Y;
r = B - r - 1;
r += A;
query[l].eb(r);
if (l > r) {
return -1;
}
}
auto check = [&](int mx)
{
priority_queue<int, vector<int>, greater<int>> pq;
for(int l = 0; l < n; ++l){
for(int r : query[l]) pq.push(r);
for(int i = 0; i < mx; ++i){
if(pq.empty()) break;
if(pq.top() < l) return false;
pq.pop();
}
}
return pq.empty();
};
if(!check(T)) return -1;
int l = 1, r = T, mid;
while(l <= r){
mid = (l + r) / 2;
if(!check(mid)) l = mid + 1;
else r = mid - 1;
}
return l;
}
#ifdef LOCAL
signed main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
int A, B, T;
cin >> A >> B >> T;
int X[A], Y[B], W[T], S[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];
for (int i = 0; i < T; ++i)
cin >> S[i];
cout << putaway(A, B, T, X, Y, W, S);
}
#endif
# | 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... |