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 <cstdio>
#include <queue>
#include <set>
using namespace std;
typedef pair<int,int> pi;
int n,k,a[100005],ret[100005];
bool vis[100005];
int sorted_pos[100005];
priority_queue<pi> pq;
int main(){
scanf("%d %d",&n,&k);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
pq.push(pi(a[i],i));
}
int pt = n;
while (!pq.empty()) {
pi t = pq.top();
pq.pop();
sorted_pos[t.second] = --pt;
if(pt >= n-k) vis[t.second] = 1,ret[pt] = t.first;
}
for (int i=0; i<n; i++) {
if(!vis[i] && i - sorted_pos[i] >= k){
ret[i - k] = a[i];
vis[i] = 1;
}
}
int p = 0;
for (int i=0; i<n; i++) {
while (ret[p]) {
p++;
}
if(!vis[i]) ret[p++] = a[i];
}
for (int i=0; i<n; i++) {
printf("%d ",ret[i]);
}
}
# | 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... |