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;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
if(B == 0) {
sort(X, X+A);
int lo = 0, hi = T;
int res=-1;
while(lo <= hi) {
int mid = (lo+hi)/2;
vector<int> v(A);
for(int i = 0;i<T;i++) {
int it = upper_bound(X, X+A, W[i])-X;
if(it == A)return -1;
v[it]++;
}
for(int i = 0;i<A-1;i++) {
if(v[i] > mid) {
v[i+1]+=v[i]-mid;
v[i]=mid;
}
}
if(v.back() > mid) {
lo = mid+1;
}
else {
res=mid;
hi=mid-1;
}
}
return res;
}
else if(A == 0) {
sort(Y, Y+B);
long long lo = 0, hi = 2*T;
long long res=-1;
while(lo <= hi) {
long long mid = (lo+hi)/2;
vector<long long> v(B);
for(long long i = 0;i<T;i++) {
long long it = upper_bound(Y, Y+B, S[i])-Y;
if(it == B)return -1;
v[it]++;
}
for(long long i = 0;i<B-1;i++) {
if(v[i] > mid) {
v[i+1]+=v[i]-mid;
v[i]=mid;
}
}
if(v.back() > mid) {
lo = mid+1;
}
else {
res=mid;
hi=mid-1;
}
}
return res;
}
sort(X, X+A);
sort(Y, Y+B);
int lo = 1, hi = 2*T;
int res=-1;
while(lo <= hi) {
int mid = (lo+hi)/2;
multiset<long long> v[A];
multiset<long long> rem2;
for(int i = 0;i<T;i++) {
int it = upper_bound(X, X+A, W[i])-X;
if(it == A)rem2.insert(S[i]);
else v[it].insert(S[i]);
}
multiset<long long> rem;
for(int i = 0;i<A;i++) {
int cnt = 0;
while(cnt <= 4*v[i].size() and rem.size() and v[i].size() and (*(--rem.end())) >= (*v[i].begin())) {
auto it = (--rem.end());
auto it2 = v[i].begin();
long long itt=*it, itt2=*it2;
rem.erase(it);
v[i].erase(it2);
v[i].insert(itt);
rem.insert(itt2);
cnt++;
}
while(v[i].size() > mid) {
auto it = v[i].begin();
rem.insert(*it);
v[i].erase(it);
}
while(rem.size()>0 and v[i].size() < mid) {
auto it = rem.end();
--it;
v[i].insert(*it);
rem.erase(it);
}
cnt=0;
while(cnt <= 4*v[i].size() and rem.size() and v[i].size() and (*(--rem.end())) >= (*v[i].begin())) {
auto it = (--rem.end());
auto it2 = v[i].begin();
long long itt=*it, itt2=*it2;
rem.erase(it);
v[i].erase(it2);
v[i].insert(itt);
rem.insert(itt2);
cnt++;
}
}
for(auto it=rem2.begin();it!=rem2.end();it++) {
rem.insert(*it);
}
vector<long long> v2(B);
for(auto it=rem.begin();it!=rem.end();++it) {
int val = (*it);
int idx=upper_bound(Y, Y+B, val)-Y;
if(idx==B)return -1;
v2[idx]++;
}
for(int i = 0;i<B-1;i++) {
if(v2[i] > mid) {
int c = v2[i]-mid;
v2[i+1]+=c;
v2[i]=mid;
}
}
if(v2.back() > mid) {
lo = mid+1;
}
else {
res=mid;
hi = mid-1;
}
}
return res;
}
Compilation message (stderr)
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:78:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | while(cnt <= 4*v[i].size() and rem.size() and v[i].size() and (*(--rem.end())) >= (*v[i].begin())) {
| ~~~~^~~~~~~~~~~~~~~~
robots.cpp:88:22: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
88 | while(v[i].size() > mid) {
| ~~~~~~~~~~~~^~~~~
robots.cpp:93:39: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
93 | while(rem.size()>0 and v[i].size() < mid) {
| ~~~~~~~~~~~~^~~~~
robots.cpp:100:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | while(cnt <= 4*v[i].size() and rem.size() and v[i].size() and (*(--rem.end())) >= (*v[i].begin())) {
| ~~~~^~~~~~~~~~~~~~~~
# | 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... |