关注
感觉思路差不多 一直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);
}
}
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
05-11 11:58
中国矿业大学 Java 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
- 1... 我因为在开水团面活水被光速开除2.0W
- 2... 作为面试官,比较喜欢听到「实习收获」回答是什么样的?5354
- 3... 字节last day,知无不言!5353
- 4... 字节剪映后端暑期面经(附timeline)5095
- 5... 你是个学计算机的大学生4936
- 6... 分享我的秋招之路(2025届版)4860
- 7... 找实习三个月,感觉已无心气4582
- 8... 🐧应届生选offer防踩坑指南:为什么"有鹅选鹅"是当前最佳策略?3760
- 9... 27届前端小趴菜如何拿下三个大厂offer 📚3744
- 10... 你的经历比较单薄, 但简历又弥补了这一点--双非仔个人简历分享3290
正在热议
更多
# 我的实习收获 #
8007次浏览 163人参与
# TP-LINK工作体验 #
46689次浏览 825人参与
# 实习吐槽大会 #
10582次浏览 44人参与
# 你的办公桌上都有什么? #
6011次浏览 50人参与
# 晒一晒你的工位 #
77424次浏览 258人参与
# 入职第三天,晒晒你的工位 #
30701次浏览 145人参与
# 实习中的菜狗时刻 #
359108次浏览 3270人参与
# 今年形式下双非本找得到工作吗 #
137768次浏览 1042人参与
# Offer比较,求稳定还是求发展 #
52374次浏览 248人参与
# 来选选带哪个offer回家过年 #
659630次浏览 5271人参与
# 工作压力大怎么缓解 #
77995次浏览 927人参与
# 薪资一样,你会选择去大厂还是小公司 #
19281次浏览 116人参与
# 电网笔面经互助 #
33214次浏览 331人参与
# 24届的你们现状如何了? #
69444次浏览 399人参与
# 你的秋招第一场笔试是哪家 #
129385次浏览 1404人参与
# 高学历就一定能找到好工作吗? #
47257次浏览 583人参与
# 想给25届机械人的秋招建议 #
26453次浏览 219人参与
# 我的租房踩坑经历 #
1193次浏览 35人参与
# 25届非技术实习投递记录 #
116326次浏览 969人参与
# 机械人,你的秋招第一份简历被谁挂了 #
137774次浏览 1972人参与