要用longlong来存数据
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; } }
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)
排序不等式
要用longlong来存数据
include
排序不等式