Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- signed main()
- {
- int n;
- cin>>n;
- vector<int> v(n);
- int sum = 0;
- for(int i =0; i<n; i++){
- cin>>v[i];
- sum += v[i];
- }
- sort(v.begin() , v.end());
- reverse(v.begin() , v.end());
- int m = n-1,ans = 0;
- for(int i=0; i<n; i++){
- ans += v[i]*(n - i);
- ans -= sum;
- sum -= v[i];
- }
- cout<<ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement