[KOI]전국본선 2013 중등부 첫번째 문제





#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

struct ANIMAL {
	int y, x;
};

vector<int> hunter;
vector<animal> animal;

bool comp(const ANIMAL& a, const ANIMAL& b) {
	return (a.x < b.x);
}

bool is_kill(const ANIMAL& a, const int h, const int len) {
	int dist = abs(a.x - h) + a.y;
	if (dist <= len)		return true;
	else					return false;
}

int main()
{
	int M, N, L;
	scanf("%d %d %d", &M, &N, &L);

	hunter.resize(M);
	animal.resize(N);

	for (int i = 0; i < M; ++i) {
		scanf("%d", &hunter[i]);
	}

	for (int i = 0; i < N; ++i) {
		scanf("%d %d", &animal[i].x, &animal[i].y);
	}

	sort(hunter.begin(), hunter.end());
	sort(animal.begin(), animal.end(), comp);

	int ret = 0;
	for (auto ani : animal) {
		auto target = lower_bound(hunter.begin(), hunter.end(), ani.x) - hunter.begin();
		if (is_kill(ani, hunter[target], L)) {
			++ret;
		}
		else {
			if (target > 0) {
				--target;
				if (is_kill(ani, hunter[target], L)) {
					++ret;
				}
			}
		}
	}

	printf("%d\n", ret);
	
	return 0;
}


설정

트랙백

댓글