1048. 最小等待时间

humiao

要用longlong来存数据

Andrew-Malcom

include

using namespace std;
int main()
{
        int t;cin>>t;
        while(t--){
                int n;cin>>n;
                int num[n+1];
                long long int i,time=0;
                for(i=0;i<n;i++) cin>>num[i];
                sort(num,num+n);
                for(i=0;i<n-1;i++){
                        time+=(n-1-i)*num[i];
                }
                cout<<time<<endl;
        }
}
SmallY
N = int(input())
for _ in range(N):
    n = int(input())
    L = []
    for i in range(n):
        L.append(int(input()))
    L.sort()
    res = 0
    n = n - 1
    for i in range(len(L)):
        res += n*L[i]
        n -= 1
    print(res)
_纱灯_

排序不等式

你当前正在回复 博客/题目
存在问题!