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 <bits/stdc++.h>
#include "robots.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
vector <int> x, y;
vector <ar<int,2>> p;
for ( int i = 0; i < A; i++ ){
x.pb(X[i]);
}
for ( int i = 0; i < B; i++ ){
y.pb(Y[i]);
}
for ( int i = 0; i < T; i++ ){
p.pb({W[i], S[i]});
}
sort(all(p)), sort(all(x)), sort(all(y));
reverse(all(y));
auto ok = [&](int k){
priority_queue <int> q;
int j = 0;
for ( auto &i: x ){
while ( j < T && p[j][0] < i ){
q.push(p[j][1]);
j++;
}
int f = k;
while ( f > 0 && !q.empty() ){
q.pop(); --f;
}
}
while ( j < T ){
q.push(p[j][1]);
j++;
}
for ( auto &i: y ){
if ( q.empty() ) break;
if ( q.top() >= i ){
return false;
}
int f = k;
while ( f > 0 && !q.empty() ){
q.pop(), --f;
}
}
return q.empty();
};
int l = 0, r = T + 1;
while ( l < r ){
int md = (l + r) / 2;
if ( ok(md) ) r = md;
else l = md + 1;
}
if ( l == T + 1 ){
return -1;
} return l;
}
# | 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... |