tothanhhai2k05
Giới thiệu
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int x = sc.nextInt();
int arr[] = new int[N];
for(int i = 0; i < N; i++) {
arr[i] = sc.nextInt();
}
check(arr, x);
}
public static void check(int arr[], int x) {
int i = 0;
int j = arr.length - 1;
while (i < j) {
if((arr[i] + arr[j]) == x) {
System.out.println((i + 1)+ " " + (j + 1));
break;
}
if((arr[i] + arr[j] > x)) {
j -= 1;
} else {
i += 1;
}
}
if(i == j) {
System.out.println("NO solution");
}
}
}