您的位置:首页 > 其它

【BZOJ】【P2697】【特技飞行】【题解】【贪心】

2014-10-25 13:56 471 查看
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2697

水贪心

 Code:

#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int c[333];
int main(){
cin>>n>>k;
for(int i=1;i<=k;i++)cin>>c[i];
sort(c+1,c+1+k,greater<int>());
int l=1,r=n,ans=0;
for(int i=1;i<=k;i++){
ans+=(r-l)*c[i];
l++;r--;
if(l>=r)break;
}cout<<ans<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  bzoj