Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * @Author: Kabid
- * @Date: {{create_time}}
- * @Last Modified by: Kabid
- * @Last Modified time: 2021-02-18 18:02:31
- */
- #include "bits/stdc++.h"
- using namespace std;
- #define ll long long
- #define dbug cerr<<"HERE"<<endl;
- //===============Declaration=======================================
- int t;
- ll i, j; //iterators
- ll n, k , p, m, c, x; //variables;
- ll mx = LLONG_MIN, mn = LLONG_MAX; // max min
- int a [20001];
- int bs(int l, int r, int xx) {
- //cerr << "HERE" << endl;
- int mid = (l + r) / 2;
- while(l<=r){
- //cerr<<mid<<endl;
- if(a[mid]<xx)
- return bs (l+1,r,xx);
- else if(a[mid]>xx)
- return bs (l, mid-1, xx);
- else return mid;
- }
- //cerr<<"--------+"<<r-1<<endl;
- return l;
- }
- void solve();
- int main() {
- cin >> t; x = t;
- while (t-- ) {
- solve();
- }
- return 0;
- }
- void solve() {
- cin >> n; int ct = 0;
- for (i = 0; i < n; i++) {
- cin >> a[i];
- }
- sort(a, a + n);
- for (i = 0; i < n - 2; i++) {
- for (j = i + 1; j < n - 1; j++) {
- ct += bs(j + 1, n - 1, a[i] + a[j]) - j -1; //cout<<a[i]<<' '<<a[j]<<' '<<k<<' '<<j<<endl;
- }
- }
- cout << "Case " << x - t << ": " << ct << endl;
- }
- /**
- 3
- 5
- 3 12 5 4 9
- 6
- 1 2 3 4 5 6
- 4
- 100 211 212 121
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement