Hamoudi30

D - Triangles atcoder

Jul 28th, 2021 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define SZ(v) ((int)((v).size()))
  6. constexpr ll mod = 1e9+7;
  7. constexpr ll inf = 1e18+7;
  8. void run () {
  9.     int n;
  10.     cin >> n;
  11.     vector<ll> L(n);
  12.     for (ll &i : L)
  13.         cin >> i;
  14.     sort(L.begin(), L.end());
  15.     ll ans = 0;
  16.     for (int i = 0; i < n; ++i) {
  17.         for (int j = i + 1; j < n; ++j) {
  18.             ll sumOfpair = L[i] + L[j];
  19.             int k = lower_bound(L.begin(), L.end(), sumOfpair) - L.begin();
  20.             --k;
  21.             ans += max(0, k - j);
  22.         }
  23.     }
  24.     cout << ans << '\n';
  25. }
  26. int main () {
  27.     ios_base::sync_with_stdio(false);
  28.     cin.tie(nullptr);
  29.     cout.tie(nullptr);
  30. //    freopen("/home/hamoudi/clion/hello.in", "rt", stdin);
  31.     int tt;
  32.     tt = 1;
  33. //    cin >> tt;
  34.     while (tt--)
  35.         run();
  36. }
  37. /*
  38.  
  39.  */
Add Comment
Please, Sign In to add comment