Submission #554497

#TimeUsernameProblemLanguageResultExecution timeMemory
554497elazarkorenRobots (IOI13_robots)C++17
0 / 100
1392 ms20648 KiB
#include "robots.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MAX_T = 1e6 + 1;
const int MAX_A = 5e4 + 1;
const int MAX_B = 5e4 + 1;

int a, b, t;
int x[MAX_A], y[MAX_B], w[MAX_T], s[MAX_T];

int ind[MAX_T];

bool Ok(int time) {
    priority_queue<int> pq;
    int ind = 0;
    for (int i = 0; i < a; i++) {
        while (ind < t && w[ind] < x[i]) {
            pq.push(s[ind++]);
        }
        int x = time;
        while (!pq.empty() && x--) pq.pop();
    }
    while (ind < t) pq.push(s[ind++]);
    for (int i = 0; i < b && !pq.empty(); i++) {
        if (pq.top() >= y[i]) return false;
        int x = time;
        while (!pq.empty() && x--) pq.pop();
    }
    return pq.empty();
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    a = A, b = B, t = T;
    for (int i = 0; i < t; i++) {
        ind[i] = i;
        w[i] = W[i],
        s[i] = S[i];
    }
    for (int i = 0; i < a; i++) x[i] = X[i];
    for (int i = 0; i < b; i++) y[i] = Y[i];
    sort(ind, ind + t, [&] (int i, int j) {
        return w[i] < w[j];
    });
    sort(x, x + a);
    sort(y, y + b, greater<int>());
    int begin = 0, end = t + 1, mid;
    while (begin < end) {
        mid = (begin + end) >> 1;
        if (Ok(mid)) {
            end = mid;
        } else begin = mid + 1;
    }
    if (end == t + 1) return -1;
    return end;
}
#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...