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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
int n, used[N];
vector <int> x, y, w, s;
vector < pair <int, int> > v1, v2;
bool check(int c){
memset(used, 0, sizeof(used));
int pt = -1, sz = (int)x.size();
set < pair <int, int> > st;
for(int i = 0; i < sz; i ++){
while(pt + 1 < n && v1[pt + 1].first < x[i]){
pt ++;
st.insert( {-s[ v1[pt].second ], v1[pt].second} );
}
int cn = c;
while(cn > 0 && !st.empty()){
cn --;
int id = st.begin()->second;
st.erase(st.begin());
used[id] = 1;
}
}
stack <int> stk;
sz = y.size();
pt = -1;
for(int i = 0; i < sz; i ++){
while(pt + 1 < n && v2[pt + 1].first < y[i]){
pt ++;
if(!used[ v2[pt].second ])
stk.push( v2[pt].second );
}
int cn = c;
while(cn > 0 && !stk.empty()){
used[ stk.top() ] = 1;
stk.pop();
cn --;
}
}
for(int i = 0; i < n; i ++)
if(!used[i])
return 0;
return 1;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
for(int i = 0; i < A; i ++)
x.emplace_back(X[i]);
for(int i = 0; i < B; i ++)
y.emplace_back(Y[i]);
n = T;
for(int i = 0; i < T; i ++){
w.emplace_back(W[i]);
s.emplace_back(S[i]);
v1.emplace_back(W[i], i);
v2.emplace_back(S[i], i);
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
sort(x.begin(), x.end());
sort(y.begin(), y.end());
int lo = 1, hi = T;
if(!check(T)) return -1;
while(lo <= hi){
int md = (lo + hi) >> 1;
if(check(md))
hi = md - 1;
else
lo = md + 1;
}
return hi + 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... |