拼多多笔试第三题
哪位看看俺这代码哪里有问题?
package com.rockTechnology; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class Test4 { private static int minHot(int[] hot, int[] taste, int t){ if (t == 0){ return 0; } ArrayList<Integer> hotList = backTrack(hot, taste, t, 0, 0, 0, new ArrayList<Integer>(), 2); if (hotList.size() == 0){ return -1; } Collections.sort(hotList, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return o1 - o2; } }); return hotList.get(0); } private static ArrayList<Integer> backTrack(int[] hot, int[] taste, int t, int index, int tasteSum, int hotSum, ArrayList<Integer> hotList, int times) { if (tasteSum >= t){ hotList.add(hotSum); return hotList; } if (index >= hot.length){ return hotList; } if (times > 0){ backTrack(hot, taste, t, index + 1, tasteSum + taste[index], hotSum + hot[index], hotList, times - 1); } backTrack(hot, taste, t, index + 1, tasteSum, hotSum, hotList, times); return hotList; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt() + in.nextInt(); int[] hot = new int[n]; int[] taste = new int[n]; int t = in.nextInt(); for (int i = 0; i < n; i++) { hot[i] = in.nextInt(); taste[i] = in.nextInt(); } System.out.println(minHot(hot, taste, t)); } }