Submission #1011478

#TimeUsernameProblemLanguageResultExecution timeMemory
1011478NintsiChkhaidzeRobots (IOI13_robots)C++17
100 / 100
1911 ms28352 KiB
#include "robots.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

const int N = 1e6 + 3;
pair <pair <int,int>, int> arr[N];

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    
    for (int i = 0; i < T; i++){
    	arr[i] = {{W[i],S[i]},i};
	}
	sort(arr,arr+T);
	sort(X,X + A);
	sort(Y,Y + B);
	
	int l = 1, r = T,ans = -1;
	
	while (l <= r){
		int mid = (l + r) >> 1,L = 0;
		priority_queue <int> st,st2;
		
		for (int i = 0; i < A; i++){
			while (L < T && arr[L].f.f < X[i]) {
				st.push(arr[L].f.s);
				++L;
			}
			
			int cnt = 0;
			while (st.size() && cnt < mid){
				st.pop();
				++cnt;
			}
		}
		
		while (L < T) st.push(arr[L++].f.s);
		while (st.size()) st2.push(-st.top()),st.pop();
		
		for (int i = 0; i < B; i++){
			int cnt=0;
			while (st2.size() && (-st2.top()) < Y[i] && cnt < mid){
				st2.pop();
				++cnt;
			}
		}
		
		if (!st2.size()) {
			ans = mid;
			r = mid - 1;
		}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...