Submission #779296

#TimeUsernameProblemLanguageResultExecution timeMemory
779296math_rabbit_1028로봇 (IOI13_robots)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
int a, b, t;

struct toy {
    int w, s;
    bool operator< (const toy &other) const {
        if (w == other.w) return s < other.s;
        return w < other.w;
    }
} toys[1010101];

bool compare(toy t1, toy t2) {
    if (t1.s == t2.s) return t1.w > t2.w;
    return t1.s > t2.s;
}

int wrbt[50505], srbt[50505];

priority_queue<toy> pq, pq2;

bool solve(int d) {
    while (!pq.empty()) pq.pop();
    while (!pq2.empty()) pq2.pop();

    int p = 1;
    long long remain = 0;
    for (int i = b; i >= 0; i--) {
        while (p <= t) {
            if (toys[p].s >= srbt[i]) {
                pq2.push(toys[p]);
                p++;
            }
            else break;
        }
        while (!pq2.empty()) {
            if (remain > 0) {
                pq2.pop();
                remain--;
            }
            else break;
        }
        while (!pq2.empty()) {
            pq.push(pq2.top());
            pq2.pop();
        }
        remain += d;
    }

    long long cnt = 0;
    for (int i = a; i >= 0; i--) {
        while (!pq.empty()) {
            if (pq.top().w >= wrbt[i]) {
                cnt++;
                pq.pop();
            }
            else break;
        }
        if (cnt > (long long)d * (a - i)) return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> a >> b >> t;
    for (int i = 1; i <= a; i++) cin >> wrbt[i];
    for (int i = 1; i <= b; i++) cin >> srbt[i];
    for (int i = 1; i <= t; i++) cin >> toys[i].w >> toys[i].s;

    sort(wrbt + 1, wrbt + a + 1);
    sort(srbt + 1, srbt + b + 1);
    sort(toys + 1, toys + t + 1, compare);

    for (int i = 1; i <= t; i++) {
        if (toys[i].w >= wrbt[a] && toys[i].s >= srbt[b]) {
            cout << "-1\n";
            return 0;
        }
    }

    int st = 1, ed = t;
    //assert(solve(t));
    while (st < ed) {
        int mid = (st + ed) / 2;
        if (solve(mid)) {
            ed = mid;
        }
        else {
            st = mid + 1;
        }
    }

    cout << st << "\n";

    return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc9HRfwj.o: in function `main':
robots.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc1DL6Rj.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc1DL6Rj.o: in function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status