题解
存在某种问问题顺序使得答案最小,可是我们不知道排序的规律,遂试探
给定一种排序,交换任意相邻同学问问题顺序,对答案的改变如下:
code
#include<bits/stdc++.h>
using namespace std;
struct unit
{
int s,a,e,sum;
}stu[1005];
bool cmp(unit a,unit b)
{
return a.sum<b.sum;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>stu[i].s>>stu[i].a>>stu[i].e;
stu[i].sum=stu[i].s+stu[i].a+stu[i].e;
}
sort(stu+1,stu+1+n,cmp);
long long ans=0;
for(int i=1;i<=n;i++)
{
ans+=(n-i+1)*stu[i].sum-stu[i].e;
}
cout<<ans<<endl;
return 0;
}
标签:ABC,int,sum,P8732,蓝桥,stu,2020,unit
From: https://www.cnblogs.com/pure4knowledge/p/18016489