感觉思路差不多 一直tle 求看 import java.util.*; public class Main { public static class custom implements Comparable<custom> { int num; int cash; public custom(int a, int b) { num = a; cash = b; } @Override public int compareTo(custom o) { return o.cash - this.cash; } } public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int m = s.nextInt(); int[] table = new int[n]; for (int i = 0; i < n; i++) { table[i] = s.nextInt(); } Arrays.sort(table); TreeMap<Integer, Queue<custom>> mmm = new TreeMap<>(); custom[] c = new custom[m]; for (int i = 0; i < m; i++) { c[i] = new custom(s.nextInt(), s.nextInt()); if (!mmm.containsKey(c[i].num)) { mmm.put(c[i].num, new PriorityQueue<>()); } mmm.get(c[i].num).add(c[i]); } long ans = 0; for (int i = 0; i < n; i++) { int max = 0; int index = -1; Map<Integer, Queue<custom>> tmpmap = mmm.subMap(0, table[i] + 1); Iterator<Map.Entry<Integer, Queue<custom>>> it = tmpmap.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, Queue<custom>> e = it.next(); if (e.getValue().peek().cash > max) { max = e.getValue().peek().cash; index = e.getKey(); } } ans += max; if (index != -1) { mmm.get(index).poll(); if (mmm.get(index).isEmpty()) { mmm.remove(index); } } } System.out.println(ans); } }
点赞 评论

相关推荐

程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
牛客网
牛客企业服务