Submission #638077

#TimeUsernameProblemLanguageResultExecution timeMemory
638077beaconmcRobots (IOI13_robots)C++14
0 / 100
0 ms224 KiB
#include "robots.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)



int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    sort(X,X+A);
    sort(Y,Y+B);

    FOR(i,0,T){
        W[i] = upper_bound(X,X+A, W[i]+1)-X;
    }

    



    const auto check = [&](int k) -> bool{
        priority_queue<vector<ll>, vector<vector<ll>>, greater<vector<ll>>> sus;
        priority_queue<ll, vector<ll>, greater<ll>> sus2;

        FOR(i,0,T){
            sus.push({W[i], -S[i]});
        }

        FOR(i,0,A){
            ll cnt = 0;
            while (sus.size()!=0){
                vector<ll> temp = sus.top();
                if (temp[0] > i) break;
                cnt++;
                sus.pop();
                if (cnt==k) break;

            }
        }
        while (sus.size()!=0){
            vector<ll> temp = sus.top();
            sus.pop();
            sus2.push(-temp[1]);
        }
        

        FOR(i,0,B){
            ll cnt = 0;
            while (sus2.size()!=0){

                ll temp = sus2.top();
                if (temp >= Y[i]) break;
                cnt++;
                sus2.pop();
                if (cnt==k) break;
            }
        }



        if (sus2.size()) return 0;
        else return 1;

    };
    ll lo = 0;
    ll hi = T+1;


    while (lo<hi){
        ll mid = (lo+hi)/2;
        if (check(mid)) hi = mid;
        else lo = mid + 1;

    }
    if (lo==0) lo=-1;
    return lo;

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