제출 #993293

#제출 시각아이디문제언어결과실행 시간메모리
993293Essa2006로봇 (IOI13_robots)C++14
100 / 100
1661 ms28568 KiB
#include "robots.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)


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 n = t;
    vector<array<int, 2>> A(n);
    for (int i = 0; i < n; i++) {
        A[i] = {S[i] , W[i]};
    }
    sort(all(A));
    
    int l = 0, r = n, res = -1;
    while (l <= r) {
        int md = (l + r) / 2;
        int ind = -1;
        priority_queue<array<int, 2>> pq;
        for (int i = 0; i < b; i++) {
            while (ind + 1 < n && A[ind + 1][0] < Y[i]) {
                ind++;
                pq.push({A[ind][1], ind});
            }
            
            int temp = 0;
            while (!pq.empty() && temp < md) {
                pq.pop();
                temp++;
            }
        }
        while (ind + 1 < n) {
            ind++;
            pq.push({A[ind][1], ind});
        }
        
        for (int i = a - 1; i >= 0; i--) {
            int temp = 0;
            while (!pq.empty() && temp < md) {
                array<int, 2> cur = pq.top();
                if (cur[0] >= X[i]) {
                    break;
                }
                pq.pop();
                temp++;
            }
        }
        
        if (pq.empty()) {
            res = md, r = md - 1;
        }
        else {
            l = md + 1;
        }
    }
    
    return res;

}
#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...