题目链接
题解
好水好水的贪心。。。
容易发现每种特技只表演两次,多表演没有意义,而且差距越长收益越大
然后就可以贪,最大的放两端,次大的往里,然后是第三大.......
证明很简单,假设将两个特技时间交换,那么会产生交换距离乘以(C)的差值的贡献,显然就不优
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 1005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int n,K,C[maxn];
int main(){
n = read(); K = read();
REP(i,K) C[i] = read();
LL ans = 0;
sort(C + 1,C + 1 + K);
for (int i = K; i && n > 0; i--){
ans += 1ll * C[i] * (n - 1); n -= 2;
}
printf("%lld
",ans);
return 0;
}