#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
#define F(i, n) for(int i = 0; i < (n); i++)
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
using state = pair<int, int>;
multiset<state> by_weight, by_size;
F(i, T) {
by_weight.emplace(W[i], S[i]);
by_size.emplace(S[i], W[i]);
}
multiset<state> robots;
F(i, A) {
robots.emplace(0, X[i]);
}
F(i, B) {
robots.emplace(1, Y[i]);
}
int t = 0;
while(!robots.empty() && !by_weight.empty()) {
vector<state> remove;
for(auto [type, capability] : robots) {
if(type == 0) {
auto it = by_weight.lower_bound({capability, 0});
if(it != by_weight.begin()) {
--it;
by_weight.extract(it);
by_size.extract({it->second, it->first});
} else {
remove.emplace_back(type, capability);
}
} else {
auto it = by_size.lower_bound({capability, 0});
if(it != by_size.begin()) {
--it;
by_size.extract(it);
by_weight.extract({it->second, it->first});
} else {
remove.emplace_back(type, capability);
}
}
}
t++;
for(auto rem : remove) {
robots.erase(rem);
}
}
//cout << by_weight.size() << " remaining" << endl;
if(by_weight.empty()) {
return t;
} else {
return -1;
}
}
# | 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... |