import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; public class e1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int count = 0; PriorityQueue<Integer> minHeap = new PriorityQueue<>(); PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(15, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2 - o1; } }); int n = scanner.nextInt(); for (int i = 0; i < n; i++) { int num = scanner.nextInt(); if (count % 2 == 0) { maxHeap.offer(num); int filteredMaxNum = maxHeap.poll(); minHeap.offer(filteredMaxNum); } else { minHeap.offer(num); int filteredMinNum = minHeap.poll(); maxHeap.offer(filteredMinNum); } count++; } int m = scanner.nextInt(); for (int i = 0; i < m; i++) { int num = scanner.nextInt(); if (count % 2 == 0) { maxHeap.offer(num); int filteredMaxNum = maxHeap.poll(); minHeap.offer(filteredMaxNum); } else { minHeap.offer(num); int filteredMinNum = minHeap.poll(); maxHeap.offer(filteredMinNum); } count++; } if (count % 2 == 0) { System.out.println(new Double((minHeap.peek() + maxHeap.peek())) / 2); } else { System.out.println(new Double((minHeap.peek()))); } } } }
点赞 1

相关推荐

听说改名字就能收到offer哈:Radis写错了兄弟
点赞 评论 收藏
分享
牛客网
牛客企业服务