| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
各位大神看看,为什么C++的AC,Java一样的算法就WR???import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main{
static PriorityQueue<Integer> p = new PriorityQueue<Integer>(11,new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
static PriorityQueue<Integer> q = new PriorityQueue<Integer>();
static int[] a = new int[30005];
static int[] b = new int[30005];
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
p.clear();q.clear();
int m = cin.nextInt();
int n = cin.nextInt();
for(int i = 1; i <= m; i++)
a[i] = cin.nextInt();
for(int j = 1; j <= n; j++)
b[j] = cin.nextInt();
int i = 0, j = 1,k = 1;
while(j<=n){
if(i==b[j]){
j++;
if(p.size()<k){
p.add(q.poll());
}
System.out.println(p.peek());
k++;
}else{
i++;
if(p.size()<k){
q.add(a[i]);
p.add(q.poll());
}else if(p.peek()>a[i]){
q.add(p.poll());
p.add(a[i]);
}else{
q.add(a[i]);
}
}
}
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator