题解 | #买房#
买房
http://www.nowcoder.com/practice/edf9346066f047a9833b3284798d6c29
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int num = sc.nextInt(); for(int i = 0; i < num; ++i){ int n = sc.nextInt(); int k = sc.nextInt(); int[] res = fun(n, k); System.out.println(res[0] + " " + res[1]); } } public static int[] fun(int n , int k){ int maxV = 0; if(n <= 2){ return new int[]{0,0}; }else if(n - k < k - 1){ maxV = n - k; }else if(n - k >= k - 1){ maxV = k - 1; } maxV = maxV < 0 ? 0 : maxV; return new int[]{0, maxV}; } }