MLE问题 请各位dalao不吝赐教
  • 板块P2032 扫描
  • 楼主KN1FEAX
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/2/9 22:34
  • 上次更新2023/11/5 03:27:57
查看原帖
MLE问题 请各位dalao不吝赐教
26950
KN1FEAX楼主2021/2/9 22:34
package P2032;

import java.util.*;

class struct implements Comparable<struct> {
	public short num;
	public int id;

	public int compareTo(struct B) {
		return B.num - this.num;
	}

}

public class P2032 {
	static Comparator<struct> cmp = new Comparator<struct>() {
		public int compare(struct A, struct B) {
			return B.num - A.num;
		}
	};

	public static void main(String[] args) {
		int n, k;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		struct stk[] = new struct[235502];
		for (int i = 0; i < n; i++) {
			stk[i] = new struct();
			stk[i].num = sc.nextShort();
			stk[i].id = i;
		}
		PriorityQueue<struct> pq = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {		
			pq.add(stk[i]);
			if (i >= k - 1) {
				while (pq.peek().id < i - k + 1)
					pq.poll();
				System.out.println(pq.peek().num);
			}
			stk[i]=null;
		}

	}

}

JAVA的,MLE一个点,谢谢您

2021/2/9 22:34
加载中...