제출 #479797

#제출 시각아이디문제언어결과실행 시간메모리
479797arujbansalRobots (IOI13_robots)C++17
100 / 100
1901 ms22608 KiB
#include <bits/stdc++.h>
#include "robots.h"

using namespace std;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    vector<pair<int, int>> toys(T);
    for (int i = 0; i < T; i++)
        toys[i] = make_pair(W[i], S[i]);

    sort(toys.begin(), toys.end());

    sort(X, X + A);
    sort(Y, Y + B, greater<>());

    int low = 0, high = T, ans = T + 5;
    while (low <= high) {
        int allowed = (low + high) / 2;

        priority_queue<int> pq;

        int j = 0;
        for (int i = 0; i < A; i++) {
            int can_pick = allowed;

            while (j < T && toys[j].first < X[i])
                pq.push(toys[j++].second);

            while (!pq.empty() && can_pick > 0) {
                pq.pop();
                can_pick--;

            }
        }

        for (int i = j; i < T; i++)
            pq.push(toys[i].second);

        for (int i = 0; i < B; i++) {
            int can_pick = allowed;
            while (!pq.empty() && pq.top() < Y[i] && can_pick > 0) {
                pq.pop();
                can_pick--;
            }
        }

        if (pq.empty()) {
            high = allowed - 1;
            ans = allowed;
        } else low = allowed + 1;

    }

    return (ans < T + 5 ? ans : -1);
}


// #define MAX_A 50000
// #define MAX_B 50000
// #define MAX_T 500000

// int X[MAX_A];
// int Y[MAX_B];
// int W[MAX_T];
// int S[MAX_T];

// signed main() {
//     int A, B, T;
//     cin >> A >> B >> T;

//     for (int i = 0; i < A; i++)
//         cin >> X[i];

//     for (int i = 0; i < B; i++)
//         cin >> Y[i];

//     for (int i = 0; i < T; i++)
//         cin >> W[i] >> S[i];
        
//     int answer = putaway(A, B, T, X, Y, W, S);

//     printf("%d\n", answer);

//     return 0;
// }
#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...