# 写得好痛苦啊

``````#include <stdio.h>
#include <math.h>
#include <string.h>
void swap (int *a, int *b)
{
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}
void kuaipai(int *data1,int *data2,int a,int b)
{
int i,j=0,k=b-a,ii;
if(b-a<=0)
return;
//  { printf(" there presents a b-a<=0  and a=%d and b=%d\n",a,b);return;}
if(b-a<=1)
{
//printf(" there presents a b-a<=1  and a=%d and b=%d\n",a,b);
if(data1[a]<data1[b])
{
swap(&data1[a],&data1[b]);
swap(&data2[a],&data2[b]);
}
}
else
{
int *tmp1 = calloc(b-a+1, sizeof(int)),*tmp2 = calloc(b-a+1, sizeof(int));
//int tmp1[b-a+1],tmp2[b-a+1];
memset(tmp1,0,sizeof(tmp1));    memset(tmp2,0,sizeof(tmp2));
//for(i=a;i<=b;i++)printf("%d %d, ",data1[i],data2[i]);printf("   and a=%d and b=%d j=%d and k=%d\n",a,b,j,k);
for(i=a+1;i<=b;i++)
{
if(data1[i]>data1[a])
{
tmp1[j]=data1[i];
tmp2[j]=data2[i];
j++;
}
if(data1[i]<=data1[a])
{
tmp1[k]=data1[i];
tmp2[k]=data2[i];
k--;
}
//for(ii=0;ii<b-a+1;ii++)printf("%d %d, ",tmp1[ii],tmp2[ii]);printf("\n");
}j--;k++;tmp1[j+1]=data1[a];tmp2[j+1]=data2[a];
//for(i=0;i<b-a+1;i++)printf("%d %d, ",tmp1[i],tmp2[i]);printf("\n");
for(i=0;i<b-a+1;i++)
{
data1[a+i]=tmp1[i];
data2[a+i]=tmp2[i];
}
free(tmp1);free(tmp2);
//for(i=a;i<=b;i++)printf("%d %d, ",data1[i],data2[i]);printf("   and a=%d and b=%d j=%d and k=%d\n",a,b,j,k);
kuaipai(data1,data2,a,a+j);
kuaipai(data1,data2,a+k,b);
}
}
int main()
{

int i,j,n,k,l,K,E[11];int maxnum0,maxnum1;
scanf("%d %d",&n,&K);
int W1[n],W2[n];
memset(W1,0,sizeof(W1));    memset(W2,0,sizeof(W2));
for(i=1;i<=10;i++)
scanf("%d",&E[i]);
for(i=0;i<n;i++)
{
scanf("%d",&W1[i]);
W2[i]=i;
}
kuaipai(W1,W2,0,n-1);
//  for(i=0;i<n;i++)printf("---%d %d, ",W1[i],W2[i]);printf("\n");
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(W1[i]!=W1[j]) break;
}j--;
for(k=i;k<=j;k++)
{
maxnum0=W2[k];
maxnum1=k;
for(l=k;l<=j;l++)
if(W2[l]<maxnum0)
{
maxnum0=W2[l];
maxnum1=l;
}
swap(&W1[k],&W1[maxnum1]);
swap(&W2[k],&W2[maxnum1]);
}
i=j;
}
//  for(i=0;i<n;i++)printf("---%d %d, ",W1[i],W2[i]);printf("\n");
for(i=0;i<n;i++)
{
int tmp=(i+1)%10;if(tmp==0) tmp=10;
W1[i]+=E[tmp];
//printf("%d %d + E[%d]=%d, ",W[i][1],W[i][0],i+1,tmp);
}//printf("\n");
//  for(i=0;i<n;i++)printf("---%d %d, ",W1[i],W2[i]);printf("\n");
kuaipai(W1,W2,0,n-1);
//  for(i=0;i<n;i++)printf("---%d %d, ",W1[i],W2[i]);printf("\n");

//  for(i=0;i<n;i++)printf("%d %d, ",W[i][1],W[i][0]);printf("\n");
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(W1[i]!=W1[j]) break;
}j--;
for(k=i;k<=j;k++)
{
maxnum0=W2[k];
maxnum1=k;
for(l=k;l<=j;l++)
if(W2[l]<maxnum0)
{
maxnum0=W2[l];
maxnum1=l;
}
swap(&W1[k],&W1[maxnum1]);
swap(&W2[k],&W2[maxnum1]);
}
i=j;
}
for(i=0;i<K;i++)
printf("%d ",W2[i]+1);

}``
``````

ID
1282

6

3350

869

26%