Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pb push_back
- #define SZ(v) ((int)((v).size()))
- constexpr ll mod = 1e9+7;
- constexpr ll inf = 1e18+7;
- void run () {
- int n;
- cin >> n;
- vector<ll> L(n);
- for (ll &i : L)
- cin >> i;
- sort(L.begin(), L.end());
- ll ans = 0;
- for (int i = 0; i < n; ++i) {
- for (int j = i + 1; j < n; ++j) {
- ll sumOfpair = L[i] + L[j];
- int k = lower_bound(L.begin(), L.end(), sumOfpair) - L.begin();
- --k;
- ans += max(0, k - j);
- }
- }
- cout << ans << '\n';
- }
- int main () {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // freopen("/home/hamoudi/clion/hello.in", "rt", stdin);
- int tt;
- tt = 1;
- // cin >> tt;
- while (tt--)
- run();
- }
- /*
- */
Add Comment
Please, Sign In to add comment