小红在小红书上面发布了篇笔记,其中第篇笔记的点赞数量为,评论数为。现在小红准备选择篇笔记作为“精选笔记合集”,合集的优秀程度为:所有笔记点赞数之和乘以评论数的最小值。 现在小红想知道,最终合集最大的优秀度是多少?
区块链毕设网qklbishe.com为您提供问题的解答
小红在小红书上面发布了篇笔记,其中第
篇笔记的点赞数量为
,评论数为
。现在小红准备选择
篇笔记作为“精选笔记合集”,合集的优秀程度为:所有笔记点赞数之和乘以评论数的最小值。
现在小红想知道,最终合集最大的优秀度是多少?
//排序,优先队列维护最大点赞数 import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); List<Integer> a = new ArrayList<>(); List<Integer> b = new ArrayList<>(); for(int i = 0; i < n; i++) { a.add(in.nextInt()); } for(int i = 0; i < n; i++) { b.add(in.nextInt()); } List<int[]> list = new ArrayList<>(); for(int i = 0; i < n; i++) { list.add(new int[]{a.get(i), b.get(i)}); } Collections.sort(list, (o1, o2) -> { if(o1[1] != o2[1]) { return Integer.compare(o2[1], o1[1]); }else { return Integer.compare(o2[0], o1[0]); } }); PriorityQueue<Integer> heap = new PriorityQueue<>(); long sum = 0; long max = 0; for(int[] arr : list) { int ai = arr[0]; int bi = arr[1]; heap.add(ai); sum += ai; if(heap.size() > k) { int remove = heap.poll(); sum -= remove; } if(heap.size() == k) { long current = sum * bi; if(current > max) { max = current; } } } System.out.print(max); } }
06:30
以上就是关于问题小红在小红书上面发布了篇笔记,其中第篇笔记的点赞数量为,评论数为。现在小红准备选择篇笔记作为“精选笔记合集”,合集的优秀程度为:所有笔记点赞数之和乘以评论数的最小值。
现在小红想知道,最终合集最大的优秀度是多少?的答案
欢迎关注区块链毕设网-
web3一级市场套利打新赚钱空投教程
区块链NFT链游项目方科学家脚本开发培训