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;
const int MAXN = 1e6 + 10;
int n, m, t;
int x[MAXN], y[MAXN];
pair<int, int> v[MAXN];
int bb();
bool test(int val);
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
n = A, m = B, t = T;
for(int i = 0; i < t; i++)
v[i] = make_pair(W[i], S[i]);
for(int i = 0; i < n; i++)
x[i] = X[i];
for(int i = 0; i < m; i++)
y[i] = Y[i];
sort(v, v + t);
sort(x, x + n);
sort(y, y + m);
reverse(v, v + t);
reverse(x, x + n);
reverse(y, y + m);
return bb();
}
int bb(){
int ini = 1, fim = t;
if(!test(t + 1)) return -1;
while(ini != fim){
int mid = (ini + fim) >> 1;
if(test(mid)) fim = mid;
else ini = mid + 1;
}
return ini;
}
bool test(int val){
int it1 = 0;
multiset<int> sobra;
multiset<int> pegando;
int podePega = val;
while(it1 != t && v[it1].first >= x[0])
sobra.insert(-v[it1++].second);
for(int i = 0; i < n; i++){
while(it1 != t && v[it1].first >= x[i + 1])
pegando.insert(-v[it1++].second);
while(!pegando.empty() && podePega){
pegando.erase(pegando.begin());
podePega--;
}
podePega += val;
while(!pegando.empty()){
sobra.insert(*pegando.begin());
pegando.erase(pegando.begin());
}
}
podePega = val;
for(int i = 0; i < m; i++){
if(-*sobra.begin() >= y[i]) return 0;
while(!sobra.empty() && podePega){
sobra.erase(sobra.begin());
podePega--;
}
podePega = val;
}
return sobra.empty();
}
# | 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... |