AcWing 1532. 找硬币--Java
原题链接
简单
作者:
Jiang锋时刻
,
2021-01-31 19:44:07
,
所有人可见
,
阅读 274
Java 代码
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] res = new int[n];
boolean flag = true;
for(int i = 0; i <n; i++) {
res[i] = sc.nextInt();
}
Arrays.sort(res);
int left = 0, right = n - 1;
while(left < right) {
if(res[left] + res[right] > m) {
right--;
} else if (res[left] + res[right] < m) {
left++;
} else {
System.out.println(res[left] + " " + res[right]);
flag = false;
break;
}
}
if(flag) {
System.out.println("No Solution");
}
}
}