#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include "robots.h"
using namespace std;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define ll long long
#define ld long double
#define ui uint64_t
#define cont(set, element) ((set).find(element) != (set).end())
/********* DEBUG *********/
template <typename T>
void outvec(const vector<T>& Z){
for (const T& x : Z)
cout << x << ' ';
cout << "\n";
}
void printVariable(const any& var) {
if (!var.has_value()) {
cout << "null";
return;
}
if (var.type() == typeid(int)) {
cout << any_cast<int>(var);
} else if (var.type() == typeid(double)) {
cout << any_cast<double>(var);
} else if (var.type() == typeid(float)) {
cout << any_cast<float>(var);
} else if (var.type() == typeid(char)) {
cout << any_cast<char>(var);
} else if (var.type() == typeid(bool)) {
cout << (any_cast<bool>(var) ? "true" : "false");
} else if (var.type() == typeid(string)) {
cout << any_cast<string>(var);
} else if (var.type() == typeid(const char*)) {
cout << any_cast<const char*>(var);
} else if (var.type() == typeid(long long)) {
cout << any_cast<long long>(var);
} else {
cout << "[unknown type]";
}
}
template<typename... Args>
void outval(Args... args) {
vector<any> variables = {args...};
for (size_t i = 0; i < variables.size(); ++i) {
printVariable(variables[i]);
if (i != variables.size() - 1) {
cout << " ";
}
}
cout << "\n";
}
#define nl "\n"
#define sp << " " <<
/********* DEBUG *********/
const ll MOD = 1000000007;
const ll mxN = 1000005;
struct toy{
int size, weight, i;
};
int n,a,b;
vector<toy> S_toy, W_toy;
vector<int> X_W, Y_S;
vector<bool> vis;
bool cmpW(toy &A, toy &B){
return A.weight < B.weight;
}
bool cmpS(toy &A, toy &B){
return A.size < B.size;
}
bool check(int t){
int out = n, ptr = 0;
priority_queue<pair<int,int>> pq;
for (int i = 0; i < a; i++){
while (ptr < n && (vis[W_toy[ptr].i] || W_toy[ptr].weight < X_W[i])){
if (!vis[W_toy[ptr].i]){
pq.push({W_toy[ptr].size, W_toy[ptr].i});
}
ptr++;
}
int hi = t;
while (hi && sz(pq)){
auto [val, idx] = pq.top();
pq.pop();
vis[idx] = true;
//outval("bluh:",idx);
out--; hi--;
}
}
while (sz(pq))
pq.pop();
ptr = 0;
for (int i = 0; i < b; i++){
while (ptr < n && (vis[S_toy[ptr].i] || S_toy[ptr].size < Y_S[i])){
if (!vis[S_toy[ptr].i]){
pq.push({S_toy[ptr].weight, S_toy[ptr].i});
}
ptr++;
}
int hi = t;
while (hi && sz(pq)){
auto [val, idx] = pq.top();
pq.pop();
vis[idx] = true;
//outval("bluh:",idx);
out--; hi--;
}
}
return out == 0;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
int hi = T, lo = 1;
a=A;
b=B;
n=T;
S_toy.resize(T);
W_toy.resize(T);
X_W.resize(A);
Y_S.resize(B);
vis.resize(T, false);
for (int i = 0; i < T; i++){
S_toy[i]=W_toy[i]={S[i],W[i],i};
}
sort(all(S_toy),cmpS);
sort(all(W_toy),cmpW);
for (int i =0; i < A; i++){
X_W[i] = X[i];
}
for (int i = 0; i < B; i++){
Y_S[i] = Y[i];
}
sort(all(X_W));
sort(all(Y_S));
while (lo < hi){
int m = (lo + hi) / 2;
if (check(m))
hi = m;
else
lo = m+1;
vis.assign(T, false);
}
if (check(lo))
return lo;
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... |