이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 5e4+5;
const int maxt = 1e6+5;
int n, m, t;
int x[maxn], y[maxn];
int w[maxt], s[maxt];
vector< ii > vec;
bool works(int lim)
{
vector<int> rem;
if(n == 0)
{
for(int i = 0; i< t; i++) rem.pb(vec[i].Y);
}
else
{
int pt = 0;
priority_queue<int> pq;
for(int i = 0; i< n; i++)
{
while(pt< t && vec[pt].X< x[i])
{
pq.push(vec[pt].Y);
pt++;
}
int times = lim;
while(!pq.empty() && times--) pq.pop();
}
while(!pq.empty())
{
rem.pb(pq.top()); pq.pop();
}
while(pt< t) rem.pb(vec[pt++].Y);
}
sort(rem.begin(), rem.end());
int k = rem.size();
int pt = 0, cnt = 0;
for(int i = 0; i< m; i++)
{
while(pt< k && rem[pt]< y[i]) pt++, cnt++;
cnt = max(cnt-lim, 0);
}
while(pt< k) pt++, cnt++;
return cnt == 0;
}
int putaway(int A, int B, int T, int _X[], int _Y[], int _W[], int _S[])
{
for(int i = 0; i< A; i++) x[i] = _X[i];
for(int i = 0; i< B; i++) y[i] = _Y[i];
for(int i = 0; i< T; i++)
{
w[i] = _W[i];
s[i] = _S[i];
}
n = A; m = B; t = T;
for(int i = 0; i< t; i++) vec.pb(ii(w[i], s[i]));
sort(vec.begin(), vec.end());
sort(x, x+n); sort(y, y+m);
int lo = 1, hi = T;
while(lo< hi)
{
int mid = (lo+hi)/2;
if(works(mid)) hi = mid;
else lo = mid+1;
}
if(works(lo)) return lo;
return -1;
}
# | 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... |