加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

B类——Stas and the Queue at the Buffet

发布时间:2020-12-14 04:33:05 所属栏目:大数据 来源:网络整理
导读:http://codeforces.com/contest/1151/problem/D 题意: n个学生,每个学生都有自己的位置,最后要使 最小,求最小的总和 题解: 开始各种排序(a,b同时排,a-b和a,b同时排),都不对,其实只要给ai-bi排序就行。。 代码: #includeiostream #include algorit

http://codeforces.com/contest/1151/problem/D

题意:

n个学生,每个学生都有自己的位置,最后要使

最小,求最小的总和

题解:

开始各种排序(a,b同时排,a-b和a,b同时排),都不对,其实只要给ai-bi排序就行。。

代码:

#include<iostream>
#include<algorithm>
using namespace std;
struct node{
    long long a,b;
}stu[100010];
int cmp(const node x,const node y){
    return (x.a-x.b)>(y.a-y.b);
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>stu[i].a>>stu[i].b;
       // a[i]=stu[i].a-stu[i].b;
    }
    sort(stu,stu+n,cmp);
    long long sum=0;
    for(int i=0;i<n;i++){
        sum+=stu[i].a*(i+1-1)+stu[i].b*(n-i-1);
        //cout<<sum<<endl;
    }
    cout<<sum<<endl;
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读