Submission #116187

#TimeUsernameProblemLanguageResultExecution timeMemory
116187nvmdavaRobots (IOI13_robots)C++17
76 / 100
3045 ms25108 KiB
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> toy;
vector<int> w, s;
int ss, ww, tt;
multiset<int> in;

bool pos(int t){
	
	in.clear();
	int now = 0;
	for(int i = 0; i < ww; i++){
		while(now < tt && toy[now].first < w[i]){
			in.insert(toy[now].second);
			now++;
		}
		for(int j = 0; j < t; j++){
			if(in.empty()) break;
			in.erase(--in.end());
		}
	}
	
	for(; now < tt; now++)
		in.insert(toy[now].second);
	if(in.empty())return 1;
	
	for(int i = ss - 1; i >= 0; i--){
		if(*(--in.end()) >= s[i]) return 0;
		
		for(int j = 0; j < t; j++){
			in.erase(--in.end());
			if(in.empty()) return 1;
		}
	}
	if(in.empty()) return 1;
	return 0;
	
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
	for(int i = 0; i < T; i++)
		toy.push_back({W[i], S[i]});
	
	for(int i = 0; i < A; i++)
		w.push_back(X[i]);
		
	for(int i = 0; i < B; i++)
		s.push_back(Y[i]);
	
	ss = B;
	ww = A;
	tt = T;
	
	sort(toy.begin(), toy.end());
	sort(w.begin(), w.end());
	sort(s.begin(), s.end());
	
	int l = 0, r = 1000001;
	int m;
	
	while(l != r){
		m = (l + r) >> 1;
		if(pos(m)) r = m;
		else l = m + 1;
	}
	if(r == 1000001) return -1;
	return r;
}
#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...