Submission #305329

#TimeUsernameProblemLanguageResultExecution timeMemory
305329TemmieRobots (IOI13_robots)C++17
14 / 100
1110 ms20764 KiB
#include <bits/stdc++.h>
#include "robots.h"

typedef long long ll;

struct Toy {
	ll w, s;
	Toy(int W = 0, int S = 0) : w(W), s(S) { }
	bool operator<(const Toy& other) const {
		if (w == other.w) return s < other.s;
		return w < other.w;
	}
};

int putaway(int a, int b, int t, int X[], int Y[], int W[], int S[]) {
	std::vector <int> x(a); for (int i = 0; i < a; i++) x[i] = X[i];
	std::vector <int> y(b); for (int i = 0; i < b; i++) y[i] = Y[i];
	std::vector <int> w(t); for (int i = 0; i < t; i++) w[i] = W[i];
	std::vector <int> s(t); for (int i = 0; i < t; i++) s[i] = S[i];
	std::vector <Toy> toy(t);
	for (int i = 0; i < t; i++) toy[i] = Toy(w[i], s[i]);
	std::sort(toy.begin(), toy.end());
	std::sort(x.begin(), x.end());
	std::sort(y.rbegin(), y.rend());
	ll l = 1, r = t + 1;
	while (l < r) {
		ll mid = (l + r) >> 1LL, toys = 0;
		std::priority_queue <ll> pq;
		for (int i = 0; i < a; i++) {
			while (toys < t && toy[pq.size()].w < x[i])
				pq.push(toy[toys].s), toys++;
			ll tmp = mid;
			while (pq.size() && tmp--) pq.pop();
		}
		while (toys < t) pq.push(toy[toys].s), toys++;
		bool brk = false;
		for (int i = 0; i < b; i++) {
			ll tmp = mid;
			while (pq.size() && tmp--) {
				if (pq.top() >= y[i]) {
					l = mid + 1LL;
					brk = true; break;
				}
				pq.pop();
			}
			if (brk) break;
		}
		if (brk) continue;
		if (pq.empty()) r = mid;
		else l = mid + 1LL;
	}
	if (l == t + 1) return -1;
	return l;
}
#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...