Skip to content

Commit 4e75a48

Browse files
committed
atcoder/abc186D
1 parent 52270d8 commit 4e75a48

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

atcoder/abc186/D/main.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int N;
12+
vector<ll> A;
13+
14+
cin >> N;
15+
A.assign(N, 0);
16+
for (auto &a : A) cin >> a;
17+
18+
sort(A.begin(), A.end());
19+
ll rhs = 0;
20+
for (int i = 0; i < N; ++i) {
21+
rhs += (N - i) * A[i];
22+
}
23+
ll lhs = 0;
24+
for (int i = N - 1; i >= 0; --i) {
25+
if (i + 1 < N) {
26+
A[i] += A[i+1];
27+
}
28+
lhs += A[i];
29+
}
30+
ll ans = lhs - rhs;
31+
cout << ans << endl;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)