This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
using namespace std;
int n, K, H[101000], P[101000], top;
struct A{
int a, num;
bool operator<(const A &p)const{
return a < p.a;
}
}w[101000];
int main(){
int i;
scanf("%d%d", &n, &K);
for (i = 1; i <= n; i++){
scanf("%d", &w[i].a);
w[i].num = i;
}
sort(w + 1, w + n + 1);
for (i = 1; i <= n; i++){
P[w[i].num] = i;
}
for (i = 1; i <= n + K; i++){
if (i <= n){
H[top++] = -P[i];
push_heap(H, H + top);
}
if (i <= K)continue;
printf("%d ", w[-H[0]].a);
pop_heap(H, H + top);
top--;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |