---
# System prepended metadata

title: APCS機械鼠
tags: [APCS, 解析]

---

# APCS機械鼠
**簡易解析**

``` cpp=
#include<iostream>
using namespace std;
int main()
{
	int x, n, l = 0, r = 0, min = 101, max = -101;
	cin >> x >> n;
	for(int i=0 ; i<n ; i++)
	{
		int food;
		cin >> food;
		if(food>x) //判斷此食物是否在老鼠的右邊
		{
			r++; //紀錄老鼠右邊的食物有幾個
			if(food>max) //找最右邊的值(max)
			max = food;
		}
		else if(food<x) //判斷此食物是否在老鼠的左邊
		{
			l++; //紀錄老鼠左邊的食物有幾個
			if(food<min) //找最左邊的值(min)
			min = food;
		}
	}
	l < r ? cout << r << " " << max : cout  << l << " " << min;
       //如果左邊比右邊少 輸出右邊數量及max 反之 輸出左邊數量及min
	return 0;
}
```