#38023: C++簡單明瞭


magickent07@gmail.com (gerericall)

學校 : 國立臺南高級工業職業學校
編號 : 236929
來源 : [149.88.103.36]
最後登入時間 :
2025-08-31 14:44:43

#include <iostream>
using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  int a[n];
  int b = 0; 
  int c = 0; 
  int B = x; 
  int C = x; 
  int tempB = 0;
  int tempC = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > x) 
    {
      b += 1;
      tempB = a[i];
      if (tempB > B) {
        B = tempB;
      }
    } else if (a[i] < x) 
    {
      c += 1;
      tempC = a[i];
      if (tempC < C) {
        C = tempC;
      }
    }
  }
  if (b > c) {
    cout << b << " " << B << endl;
  } else {
    cout << c << " " << C << endl;
  }
}