import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] base = in.nextLine().split(" "); int n = Integer.valueOf(base[0]); int m = Integer.valueOf(base[1]); //货物 String[] shops = in.nextLine().split(" "); String[] helpers = new String[m]; for (int i = 0; i < m; i ++){ helpers[i] = in.nextLine(); } int result = 0; int[][] money = new int[m][4]; Set<Integer> check = new HashSet<>(); for (int i = 0; i < m; i ++){ String[] temp = helpers[i].split(" "); money[i][1] = Integer.valueOf(temp[0]); //优惠 money[i][0] = Integer.valueOf(temp[1]); } sortIntArray(money,new int[] {0,1}); int[] helpShow = new int[n]; for (int i = 0; i < n; i ++) { helpShow[i] = Integer.valueOf(shops[i]); result += helpShow[i]; } Arrays.sort(helpShow); for (int i = 0; i < n; i ++){ for (int j = m - 1; j >= 0; j --){ if (money[j][1] <= helpShow[i] && !check.contains(j)){ result -= money[j][0]; check.add(j); break; } } } System.out.println(result); } private static void sortIntArray(int[][] arObjects, final int[] arOrders) { Arrays.sort(arObjects, new Comparator<Object>() { public int compare(Object oObjectA, Object oObjectB) { int[] arTempOne = (int[])oObjectA; int[] arTempTwo = (int[])oObjectB; for (int i = 0; i < arOrders.length; i++) { int k = arOrders[i]; if (arTempOne[k] > arTempTwo[k]) { return 1; } else if (arTempOne[k] < arTempTwo[k]) { return -1; } else { continue; } } return 0; } }); } } 好渔夫的一个方法
点赞 评论

相关推荐

你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务