코드
import java.lang.*;
import java.util.*;
import java.io.*;
public class Main {
static int n, x;
static int[] numbers;
static int result = 0;
public static void main(String[] args) {
input();
func();
System.out.println(result);
}
static void input() {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
numbers = new int[n];
for (int i = 0; i < n; ++i) {
numbers[i] = sc.nextInt();
}
x = sc.nextInt();
sc.close();
}
static void func() {
Arrays.sort(numbers);
int left = 0;
int right = n - 1;
while (left < right) {
int sum = numbers[left] + numbers[right];
if (sum < x) {
++left;
} else {
if (sum == x) {
++result;
++left;
}
--right;
}
}
}
}