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;
using ll = long long;
ll n, m, q, k, x, y, a, b, c;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
vector< pair<ll, ll> > v;
for (int i = 0; i < T; i++) {
v.push_back({W[i], S[i]});
}
sort(v.begin(), v.end());
sort(X, X + A);
sort(Y, Y + B);
if (B == 0) {
ll l = T / (A + B), r = T + 1;
while (r > l) {
ll mid = (r + l) / 2;
// cout << mid << endl;
ll pos = 0;
ll cnt = 0;
for (int i = 0; i < A; i++) {
while (pos != T && v[pos].first < X[i]) {
cnt++;
pos++;
}
cnt -= min(cnt, mid);
}
if (cnt == 0 && pos == T) {
r = mid;
}
else {
l = mid + 1;
}
}
if (l == T + 1) {
return -1;
}
return l;
}
ll l = T / (A + B), r = T + 1;
while (r > l) {
ll mid = (r + l) / 2;
// cout << mid << endl;
ll pos = 0;
multiset<ll> st;
for (int i = 0; i < A; i++) {
while (pos != T && v[pos].first < X[i]) {
st.insert(v[pos].second);
pos++;
}
for (int j = 0; j < mid; j++) {
if (st.size() == 0) {
break;
}
// cout << i << ' ' << *st.rbegin() << endl;
st.erase(--st.end());
}
}
while (pos != T) {
st.insert(v[pos].second);
pos++;
}
// cout << st.size() << endl;
bool fl = 1;
for (int i = B - 1; i >= 0; i--) {
if (st.empty()) {
break;
}
if ((*st.rbegin()) >= Y[i]) {
fl = 0;
break;
}
for (int j = 0; j < mid; j++) {
if (st.size() == 0) {
break;
}
st.erase(--st.end());
}
}
if (st.size() != 0) {
fl = 0;
}
if (fl) {
r = mid;
}
else {
l = mid + 1;
}
}
if (l == T + 1) {
return -1;
}
return l;
}
# | 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... |