Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv)
- {
- ll n;
- const ll mod = 1e8;
- cin >> n;
- vl a(n);
- for (auto &x : a)
- cin >> x, x %= mod;
- sort(a.begin(), a.end());
- vl acc(n + 1);
- for (ll i = 0; i < n; ++i)
- acc[i + 1] = acc[i] + a[i];
- ll ans = 0;
- for (ll i = 0; i < n; ++i) {
- ll lb = lower_bound(a.begin(), a.end(), mod - a[i]) - a.begin();
- ll inc = lb;
- ll fhalf = inc * a[i] + acc[inc];
- ll shalf = (n - inc) * a[i] + (acc[n] - acc[inc]) - mod * (n - inc);
- ans += fhalf + shalf - 2 * a[i] + (inc <= i ? mod : 0);
- }
- cout << ans / 2 << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement