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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
struct S{
int w, s;
bool operator <(const S &a)const{
return w<a.w;
}
};
vector<S> v;
vector<int> x, y;
priority_queue<int> pq;
bool chk(int k){
while(!pq.empty()) pq.pop();
int j=0, t;
for(int i=0; i<v.size(); i++){
while(j<x.size() && x[j]<=v[i].w){
t = k;
while(t-- && !pq.empty()) pq.pop();
j++;
}
pq.push(v[i].s);
}
while(j<x.size()){
t = k;
while(t-- && !pq.empty()) pq.pop();
j++;
}
for(int i=y.size()-1; i>=0; i--){
t = k;
while(t-- && !pq.empty()){
if(pq.top()>=y[i]) return false;
pq.pop();
}
}
return pq.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
for(int i=0; i<A; i++) x.push_back(X[i]);
for(int i=0; i<B; i++) y.push_back(Y[i]);
for(int i=0; i<T; i++) v.push_back({W[i], S[i]});
sort(x.begin(), x.end()); sort(y.begin(), y.end()); sort(v.begin(), v.end());
int s = 1, e = 1000000, m;
while(s<e){
m = (s+e)/2;
if(chk(m)) e = m;
else s = m+1;
}
if(chk(s)) return s;
return -1;
}
Compilation message (stderr)
robots.cpp: In function 'bool chk(int)':
robots.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
~^~~~~~~~~
robots.cpp:24:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<x.size() && x[j]<=v[i].w){
~^~~~~~~~~
robots.cpp:31:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<x.size()){
~^~~~~~~~~
# | 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... |