이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#include "robots.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll weak[1000005],small[1000005],a,b,t;
pair<ll,ll>r[1000005];
ll check(ll x){
priority_queue<ll>q;
ll pos=0;
for(int i=0;i<a;i++) {
int mx = weak[i];
int cnt = 0;
while(pos<t&&r[pos].first<mx) {
q.push(r[pos].second);
pos++;
}
while(cnt<x&&!q.empty()){
q.pop();
cnt++;
}
}
for(int i=pos;i<t;i++) {
q.push(r[i].second);
}
vector<int>v;
while(!q.empty()) {
v.push_back(q.top());
q.pop();
}
reverse(v.begin(), v.end());
int sz=v.size();
pos=0;
for(int i=0;i<b;i++) {
int mx=small[i];
int cnt=0;
while(cnt<x&&pos<sz&&v[pos]<mx){
pos++;
cnt++;
}
}
return (pos >= sz);
}
ll bs(ll l,ll r){
if(l==r){
if(check(l)==1){
return l;
}else return -1;
}
ll mid=(l+r)/2;
if(check(mid)){
return bs(l,mid);
}else return bs(mid+1,r);
}
int putaway(int A,int B,int T,int X[],int Y[],int W[],int S[]){
a=A;
b=B;
t=T;
for(ll i=0;i<a;i++){
weak[i]=X[i];
}
for(ll i=0;i<b;i++)
{
small[i]=Y[i];
}
sort(weak,weak+a);
sort(small,small+b);
for(ll i=0;i<t;i++)
{
r[i]=mp(W[i],S[i]);
}
sort(r,r+t);
return bs(1,t);
}
/*
int32_t main(){
CODE_START;
int XX[25],YY[25];
XX[0]=2;
XX[1]=5;
YY[0]=2;
int WW[]={3,5,2};
int SS[]={1,3,2};
cout<<putaway(2,1,3,XX,YY,WW,SS)<<endl;
}
*/
# | 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... |