我这第一题为啥才过了百分之9啊。。。 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int m = sc.nextInt(); long res = 0; PriorityQueue<Integer> minHeap = new PriorityQueue<>(); for (int i = 0; i < n; i++) { int num = sc.nextInt(); if (i < m) { minHeap.add(num); res+=num; } else { if (num > minHeap.peek()) { res-=minHeap.poll(); minHeap.add(num); res+=num; } } } System.out.println(res); } } }
点赞 8

相关推荐

牛客网
牛客企业服务