求助,第二个案例过不了,代码如下

ACwing上面都过了,这里过不了啊

import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static String next()throws Exception{
        while (st==null||!st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    static String nextLine()throws Exception{
        while (st==null||!st.hasMoreTokens())
            st = new StringTokenizer(br.readLine(),"\n");
        return st.nextToken();
    }
    static int nextInt()throws Exception{
        return Integer.parseInt(next());
    }
    static PriorityQueue<Integer> maxHeap,minHeap;
    public static void main(String[] args) throws Exception {
    	int p = nextInt();
    	String[] ar;
    	String s;
    	for(int i=0;i<p;i++) {
    		minHeap = new PriorityQueue<>();
    		maxHeap = new PriorityQueue<>((x,y)->{return y-x;});
    		LinkedList<Integer> result = new LinkedList<>();
    		int a = nextInt();
    		int d=0;//个数
    		int b = nextInt();
    		int g = b;
    		for(;b>0;b-=10) {
    			s = nextLine();
    			ar = s.split(" ");
    			for(String str : ar) {
    				d++;
    				int mid = (d+1)/2;
    				int x = Integer.parseInt(str);
    				//插入
    				if(minHeap.isEmpty() || x >= minHeap.peek()) minHeap.offer(x);
    				else maxHeap.offer(x);
    				//调整
       				while(minHeap.size()>mid) maxHeap.offer(minHeap.poll());
    				while(minHeap.size()<mid) minHeap.offer(maxHeap.poll());
    				if(d%2==1) {
    					result.add(minHeap.peek());
    				}
    			}
    		}
    		out.println(a+" "+result.size());
    		for(int j=result.size();j>=10;j-=10) {
    			for(int k=0;k<10;k++) {
    				if(k!=9)out.print(result.poll()+" ");
    				else out.print(result.poll());
    			}
    			out.println();
    		}
    		if(result.size()!=0) {
    			for(int re:result) {
    				out.print(re+" ");
    			}
    			out.println();
    		}
    	}
        out.close();
    }
}

全部评论

相关推荐

one_t:硕还是本?什么岗
点赞 评论 收藏
分享
喜欢走神的孤勇者练习时长两年半:爱华,信华,等华,黑华
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务