讨论 / [Dream][C++]AC源码
LitDream 2015-07-14 21:43:15
点我顶贴 收藏 删除
#include <cstdio>

#include <cstring>

void quicksort(int a[],int start,int end){

int i=start,j=end,x=a[start];

if(j>i){

while(i<j){

while(j>i&&a[j]>=x) j--;

if(i<j) a[i++]=a[j];

while(i<j&&a[i]<=x) i++;

if(i<j) a[j--]=a[i];

}

a[i]=x;

quicksort(a,start,i-1);

quicksort(a,i+1,end);

}

}

int main(){

int n,m;

scanf("%d%d",&n,&m);

int w[n];

memset(w,0,sizeof(w));

int i;

for(i=0;i<=n-1;i++) scanf("%d",&w[i]);

int water[m];

memset(water,0,sizeof(water));

for(i=0;i<=m-1;i++) water[i]=w[i];

for(i=0;i<=n-m-1;i++) {

quicksort(water,0,m-1);

water[0]=water[0]+w[i+m];

}

quicksort(water,0,m-1);

printf("%d",water[m-1]);

return 0;

}

查看更多回复
提交回复