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;
int a, b, t;
struct toy {
int w, s;
bool operator< (const toy &other) const {
if (w == other.w) return s < other.s;
return w < other.w;
}
} toys[1010101];
bool compare(toy t1, toy t2) {
if (t1.s == t2.s) return t1.w > t2.w;
return t1.s > t2.s;
}
int wrbt[50505], srbt[50505];
priority_queue<toy> pq, pq2;
bool solve(int d) {
while (!pq.empty()) pq.pop();
while (!pq2.empty()) pq2.pop();
int p = 1;
long long remain = 0;
for (int i = b; i >= 0; i--) {
while (p <= t) {
if (toys[p].s >= srbt[i]) {
pq2.push(toys[p]);
p++;
}
else break;
}
while (!pq2.empty()) {
if (remain > 0) {
pq2.pop();
remain--;
}
else break;
}
while (!pq2.empty()) {
pq.push(pq2.top());
pq2.pop();
}
remain += d;
}
long long cnt = 0;
for (int i = a; i >= 0; i--) {
while (!pq.empty()) {
if (pq.top().w >= wrbt[i]) {
cnt++;
pq.pop();
}
else break;
}
if (cnt > (long long)d * (a - i)) return false;
}
return true;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
a = A; b = B; t = T;
for (int i = 1; i <= a; i++) wrbt[i] = X[i];
for (int i = 1; i <= b; i++) srbt[i] = Y[i];
for (int i = 1; i <= t; i++) {
toys[i].w = W[i];
toys[i].s = S[i];
}
sort(wrbt + 1, wrbt + a + 1);
sort(srbt + 1, srbt + b + 1);
sort(toys + 1, toys + t + 1, compare);
for (int i = 1; i <= t; i++) {
if (toys[i].w >= wrbt[a] && toys[i].s >= srbt[b]) {
return -1;
}
}
int st = 1, ed = t;
//assert(solve(t));
while (st < ed) {
int mid = (st + ed) / 2;
if (solve(mid)) {
ed = mid;
}
else {
st = mid + 1;
}
}
return st;
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... |