Saruman's Army

#include
#include
#include
#include
using namespace std;

#define MAX 1000
int N, R, a[MAX];

void solve()
{
	sort(a, a + N);
	int i = 0, ans = 0;
	while (i < N)
	{
		int s = a[i++];
		while (i < N && a[i] <= s + R) i++;
		int p = a[i - 1];
		while (i < N && a[i] <= p + R) i++;
		ans++;
	}
	cout << ans << endl;
}
int main()
{

	while ((~scanf_s("%d %d ", &R, &N)) && (-1 != N || -1 != R))
	{
		for (int i = 0; i < N; i++)
		{
			cin >> a[i];
		}
		solve();
	}
	//getchar();
	return 0;
}

 

你可能感兴趣的:(挑战程序设计竞赛)