Submission #703263

#TimeUsernameProblemLanguageResultExecution timeMemory
703263speedyArdaRobots (IOI13_robots)C++14
76 / 100
3050 ms35636 KiB
#include "robots.h"
#include "bits/stdc++.h"
using namespace std;
// Sol O(nlog(n)^2)
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    
    sort(X, X + A);
    sort(Y, Y + B);
    int ans = 1e9;
    vector< pair<int, int> > sorted;
    for(int i = 0; i < T; i++)
    {
        sorted.push_back({W[i], S[i]});
    }
    sort(sorted.begin(), sorted.end());
    //reverse(sorted.begin(), sorted.end());
    int l = 1, r = T;
    //cout << "hm\n";
    while(l <= r)
    {
        int m = (l + r) / 2;
        //cout << m << "\n";
        multiset<int, greater<int> > curr;
        int idx = 0;
        for(int i = 0; i < A; i++)
        {
            while(idx < T && sorted[idx].first < X[i]) {
                curr.insert(sorted[idx].second);
                idx++;
            }
            int cnt = 0;
            while(cnt < m && !curr.empty())
            {
                curr.erase(curr.begin());
                cnt++;
            }
        }
        while(idx < T) // Elements whose weights are higher than our strongest weak robot.
        {
            curr.insert(sorted[idx].second);
            idx++;
        }
        for(int i = B - 1; i >= 0; i--)
        {
            int cnt = 0;
            while(cnt < m && !curr.empty() && Y[i] > (*curr.begin()))
            {
                curr.erase(curr.begin());
                cnt++;
            }
        }

        if(curr.size() == 0)
        {
            ans = m;
            r = m - 1;
        } else
            l = m + 1;
    }

    if(ans == 1e9)
        ans = -1;
    return ans;
    //eturn 42;
}
#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...