这里有什么问题呢?爆零了,思路就是从大到小排
#include<bits/stdc++.h>
using namespace std;
int T,a,k;
struct node
{
int n,m;
}x[100005];
bool cmp(node g,node h)
{
return g.m>h.m;
}
int main()
{
cin>>T;
while(T--)
{
cin>>a;
k=0;
for(int i=1;i<=a;i++) cin>>x[i].n>>x[i].m;
sort(x+1,x+a+1,cmp);
for(int i=1;i<=a;i++) k+=x[i].n-x[i].m*(i-1);
cout<<k<<"\n";
}
return 0;
}
全部评论
(0) 回帖