We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52270d8 commit 4e75a48Copy full SHA for 4e75a48
atcoder/abc186/D/main.cpp
@@ -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