Submission #993420

#TimeUsernameProblemLanguageResultExecution timeMemory
993420MuntherCarrotRobots (IOI13_robots)C++14
100 / 100
1423 ms17064 KiB
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;

const int N = 50500;
vector<pair<int, int>> vec;
int weak[N], small[N];
int a, b, t;

bool solve(int mid){
    priority_queue<pair<int, int>> q;
    int idx = 0;
    // cout << a << endl;
    for(int i = 0; i < a; i++){
        while(idx < t && vec[idx].first < weak[i]){
            q.push({vec[idx].second, vec[idx].first});
            idx++;
        }
        int kill = mid;
        while(kill-- && q.size()){
            q.pop();
        }
    }
    while(idx < t){
        q.push({vec[idx].second, vec[idx].first});
        idx++;
    }
    vector<int> f;
    while(q.size()){
        f.push_back(q.top().first);
        q.pop();
    }
    for(int i = 0; i < b; i++){
        int kill = mid;
        while(kill-- && f.size() && f.back() < small[i]){
            f.pop_back();
        }
    }
    // if(mid == 2) cout << f.size() << endl;
    return f.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 < a; i++){
        weak[i] = X[i];
    }
    sort(weak, weak + a);
    for(int i = 0; i < b; i++){
        small[i] = Y[i];
    }
    sort(small, small + b);
    for(int i = 0; i < t; i++){
        vec.push_back({w[i], s[i]});
    }
    sort(vec.begin(), vec.end());
    int l = 1, r = t, ans = -1;
    while(l <= r){
        int mid = (l + r) / 2;
        // cout << "-> " << mid << endl;
        if(solve(mid)){
            r = mid - 1;
            ans = mid;
        }
        else{
            l = mid + 1;
        }
    }
    return ans;
}
#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...