5
10
2016
0

[BZOJ2697] 特技飞行

贪心的做

因为只做一次特技显然没用

我们要把价值最大的特技安排在两端

然后贪心的做特技就好了

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
 
int n,k,c[1005],ans;
 
int main(){
freopen("2697.in","r",stdin);
freopen("2697.out","w",stdout);
scanf("%d %d",&n,&k);
for(int i=1;i<=k;i++)scanf("%d",&c[i]);
sort(c+1,c+k+1);
for(int i=k;i>=1 && n>1;i--,n-=2){ans+=c[i]*(n-1);}
printf("%d\n",ans);
return 0;
}
Category: BZOJ | Tags: OI bzoj | Read Count: 384

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com