全部评论
每次遇到玩具,就把玩具的时间加入小根堆,遇到猫就从小根堆里拿一个时间,如果时间比直接摸的时间小就用堆顶时间,否则就直接摸。
最小堆就行
import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int T = sc.nextInt(); int[] toy=new int[k]; for (int i = 0; i < k; i++) { toy[i]= sc.nextInt(); } int res=0; PriorityQueue<Integer> pq=new PriorityQueue<>(); for (int i = 0; i < n; i++) { int x=sc.nextInt(); if(pq.size()==0&&x==0){ res+=T; }else if(x>0&&x-1<k&&toy[x-1]<T){//key point pq.add(toy[x-1]); }else if(x==0){ res+=pq.poll(); } } System.out.println(res); } }
优先队列
直接模拟过程即可
相关推荐
02-24 19:45
西南大学 后端工程师
程序员小白条:简历写的有点太多了,一般两页是实习经历比较多的情况下,要么自己有一些有影响力的开源项目,如果你走软件,硬件没必要实习,学校安排总是没区分度的,央国企最好有中大厂实习,另外学历比较重要,不是都要求硕士的,技术会比互联网要求低一些 点赞 评论 收藏
分享
查看11道真题和解析