Advertisement
pb_jiang

ABC353C

May 11th, 2024
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  8.  
  9. using ll = long long;
  10. using pii = pair<int, int>;
  11. using pll = pair<ll, ll>;
  12. using vl = vector<ll>;
  13. using vi = vector<int>;
  14.  
  15. int main(int argc, char **argv)
  16. {
  17.     ll n;
  18.     const ll mod = 1e8;
  19.     cin >> n;
  20.     vl a(n);
  21.     for (auto &x : a)
  22.         cin >> x, x %= mod;
  23.  
  24.     sort(a.begin(), a.end());
  25.     vl acc(n + 1);
  26.     for (ll i = 0; i < n; ++i)
  27.         acc[i + 1] = acc[i] + a[i];
  28.  
  29.     ll ans = 0;
  30.     for (ll i = 0; i < n; ++i) {
  31.         ll lb = lower_bound(a.begin(), a.end(), mod - a[i]) - a.begin();
  32.         ll inc = lb;
  33.         ll fhalf = inc * a[i] + acc[inc];
  34.         ll shalf = (n - inc) * a[i] + (acc[n] - acc[inc]) - mod * (n - inc);
  35.         ans += fhalf + shalf - 2 * a[i] + (inc <= i ? mod : 0);
  36.     }
  37.  
  38.     cout << ans / 2 << endl;
  39.     return 0;
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement