# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722848 | joelgun14 | Robots (IOI13_robots) | C++17 | 3015 ms | 44012 KiB |
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 putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
// bsta
// cari max
vector<pair<int, int>> a;
sort(X, X + A);
sort(Y, Y + B);
for(int i = 0; i < T; ++i) {
a.push_back(make_pair(W[i], S[i]));
}
int l = 1, r = T, ans = -1;
sort(a.begin(), a.end());
while(l <= r) {
int mid = (l + r) / 2;
// try max mid
// putaway
// ambil dr w terbesar yg bs diambil s nya
multiset<int> avail;
// x -> weight limit
// y -> size limit
for(int i = B - 1; i >= 0; --i) {
for(int j = 0; j < mid; ++j) {
avail.insert(Y[i]);
if(avail.size() == T)
break;
}
if(avail.size() == T)
break;
}
bool done[T];
memset(done, 0, sizeof(done));
for(int i = T - 1; i >= 0; --i) {
if(avail.upper_bound(a[i].second) != avail.end()) {
avail.erase(avail.upper_bound(a[i].second));
done[i] = 1;
}
}
avail.clear();
for(int i = A - 1; i >= 0; --i) {
for(int j = 0; j < mid; ++j) {
avail.insert(X[i]);
if(avail.size() == T)
break;
}
if(avail.size() == T)
break;
}
for(int i = T - 1; i >= 0; --i) {
if(!done[i]) {
if(avail.upper_bound(a[i].first) != avail.end()) {
avail.erase(avail.upper_bound(a[i].first));
done[i] = 1;
}
}
}
bool alldone = 1;
for(int i = 0; i < T; ++i)
alldone &= done[i];
if(alldone)
ans = mid, r = mid - 1;
else
l = mid + 1;
// next ambil dr s terbesar yg bs diambil w nya
}
return ans;
}
Compilation message (stderr)
# | 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... |