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;
typedef pair<int, int> pii;
int n, m;
int a[100009];
pii b[100009];
int c[100009];
int d[100009];
void doo(int si,int ei)
{
int i,j,k;
sort(b+si,b+ei);
for(i=0;i<m && ei-i-1>=si;i++)
{
c[b[ei-i-1].second] = 1;
}
k=si;
for(i=si;i<ei;i++)
if(c[i]==0)
d[k++] = a[i];
j=ei-m;
if(j<si)j=si;
for(;j<ei;j++)
{
d[k++] = b[j].first;
}
}
int main()
{
int i, j, k, l;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++){scanf("%d",&a[i]);b[i].first = a[i];b[i].second = i; c[i]=0;}
int cur=a[0];
int ci=0;
for(i=1;i<=n;i++)
{
if(i==n || cur <= a[i])
{
doo(ci,i);
if(i==n)break;
if(cur==a[i])ci=i;
else {cur=a[i];ci=i;}
continue;
}
}
for(i=0;i<n;i++)
printf("%d ",d[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... |