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;
// Sol O(nlog(n)^2)
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
sort(X, X + A);
sort(Y, Y + B);
int ans = 1e9;
vector< pair<int, int> > sorted;
for(int i = 0; i < T; i++)
{
sorted.push_back({W[i], S[i]});
}
sort(sorted.begin(), sorted.end());
//reverse(sorted.begin(), sorted.end());
int l = 1, r = T;
//cout << "hm\n";
while(l <= r)
{
int m = (l + r) / 2;
//cout << m << "\n";
//unordered_set<int, greater<int> > curr;
priority_queue<int> curr;
int idx = 0;
for(int i = 0; i < A; i++)
{
while(idx < T && sorted[idx].first < X[i]) {
curr.push(sorted[idx].second);
idx++;
}
int cnt = 0;
while(cnt < m && !curr.empty())
{
curr.pop();
cnt++;
}
}
while(idx < T) // Elements whose weights are higher than our strongest weak robot.
{
curr.push(sorted[idx].second);
idx++;
}
for(int i = B - 1; i >= 0; i--)
{
int cnt = 0;
while(cnt < m && !curr.empty() && Y[i] > (curr.top()))
{
curr.pop();
cnt++;
}
}
if(curr.size() == 0)
{
ans = m;
r = m - 1;
} else
l = m + 1;
}
if(ans == 1e9)
ans = -1;
return ans;
//return 42;
}
# | 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... |