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>
using namespace std;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e6 + 10;
int n, a, b, x[maxn], y[maxn], w[maxn], s[maxn];
vector<int> val[maxn];
bool check(int k){
priority_queue<int> q;
for (int i = 0; i < a; i++){
for (auto x: val[i]) q.push(x);
int tmp = k;
while(tmp > 0 && !q.empty()){
q.pop();
tmp--;
}
}
for (auto x: val[a]) q.push(x);
for (int i = b-1; ~i; i--){
if (q.empty()) continue;
if (q.top() >= y[i]) break;
int tmp = k;
while(tmp > 0 && !q.empty()){
q.pop();
tmp--;
}
}
return q.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
n = T;
a = A;
b = B;
for (int i = 0; i < a; i++) x[i] = X[i];
for (int i = 0; i < b; i++) y[i] = Y[i];
for (int i = 0; i < n; i++){
w[i] = W[i];
s[i] = S[i];
}
sort(x, x+a);
sort(y, y+b);
for (int i = 0; i < n; i++){
int idx = upper_bound(x, x + a, w[i]) - x;
val[idx].push_back(s[i]);
}
int l = 0, r = n+1;
while(l + 1 < r){
int mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid;
}
return (r == n+1? -1: r);
}
# | 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... |