Submission #373642

#TimeUsernameProblemLanguageResultExecution timeMemory
373642cheissmartRobots (IOI13_robots)C++14
76 / 100
3073 ms9372 KiB
#include "robots.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define V vector
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << ") -> " << #x << " is " << (x) << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int putaway(int A, int B, int T, int a[], int b[], int W[], int S[]) {
	sort(a, a + A), sort(b, b + B);
	vi p(T);
	iota(ALL(p), 0);
	sort(ALL(p), [&] (int a, int b) {
		return S[a] < S[b];
	});
	auto ok = [&] (int k) { // each people can kill at msot k things
		set<pi> ms, ms2;
		for(int i = A - 1; i >= 0; i--) ms.insert({a[i], i});
		for(int i = B - 1; i >= 0; i--) ms2.insert({b[i], i});
		vi cnt(A), cnt2(B);
		for(int i = T - 1; i >= 0; i--) {
			int x = W[p[i]], y = S[p[i]];
			if(ms.size() && ms.upper_bound(MP(x, INF)) != ms.end()) {
				auto it = ms.upper_bound(MP(x, INF));
				cnt[it -> S]++;
				if(cnt[it -> S] == k) ms.erase(it);
			} else {
				if(ms2.empty() || ms2.upper_bound(MP(y, INF)) == ms2.end())
					return false;
				auto it = ms2.upper_bound(MP(y, INF));
				cnt2[it -> S]++;
				if(cnt2[it -> S] == k) ms2.erase(it);
			}
		}
		return true;
	};

	int lb = 1, rb = T;
	while(lb <= rb) {
		int mb = (lb + rb) / 2;
		if(ok(mb)) rb = mb - 1;
		else lb = mb + 1;
	}
	if(lb > T) return -1;
	return lb;
}

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