제출 #578836

#제출 시각아이디문제언어결과실행 시간메모리
578836Belgutei로봇 (IOI13_robots)C++17
100 / 100
1565 ms22452 KiB
#include "robots.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

const int N = 1000005;

int l,r;
pair<int,int> p[N];
priority_queue<int> pq;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    l = 1; 
    r = T;
    
    //
    for(int i = 0; i < T; i ++) {
        p[i].ff = W[i];
        p[i].ss = S[i];
    }
    sort(X, X + A);
    sort(Y, Y + B);
    sort(p, p + T);
    for(int i = 0; i < T; i ++) {
        if(p[i].ff < X[A - 1] || p[i].ss < Y[B - 1]) continue;
        return -1;
    }
    //

    while(l < r) {
        int mid = (l + r) / 2;
        int pos = 0;
        for(int i = 0; i < A; i ++) {
            while(pos < T && p[pos].ff < X[i]) {
                pq.push(p[pos].ss);
                pos ++;
            }
            int tmp = mid;
            while(tmp -- && pq.size() > 0) {
                pq.pop();
            }
        }
        while(pos < T) {
            pq.push(p[pos].ss);
            pos ++;
        }
        for(int i = B - 1; i >= 0; i --) {
            int tmp = mid;
            while(tmp -- && pq.size() > 0 && pq.top() < Y[i]) {
                pq.pop();
            }
        }
        if(pq.size() == 0) {
            r = mid;
        }
        else {l = mid + 1;}
        while(pq.size() > 0) {
            pq.pop();
        }
    }
    return l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...