import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
String first[]=bufferedReader.readLine().split(" ");
int n=Integer.parseInt(first[0]);
int m=Integer.parseInt(first[1]);
int val[]=new int[n];
String sec[]=bufferedReader.readLine().split(" ");
for (int i=0;i<n;i++){
val[i]=Integer.parseInt(sec[i]);
}
Arrays.sort(val);
int low=0,high=n-1;
while (low<high){
if (val[low]+val[high]>m){
high--;
} else if (val[low]+val[high]<m) {
low++;
} else if (val[low]+val[high]==m) {
System.out.println(val[low]+" "+val[high]);
return;
}
}
System.out.println("No Solution");
}
}
1048.Find Coins Java
于 2024-02-20 17:56:40 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)