Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
517 B
6
Indexable
#include <iostream>
#include <algorithm>
using namespace std;

int n, cnt, a[100000];

int main() {
    cin >> n; for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    
    cnt = 0;
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            if(binary_search(a+j+1, a+n, a[i]+a[j])){
                cnt++;
                //cout << i << " " << j << " " << a[i] << " " << a[j] << endl;
            }
        }
    }
    cout << 2*cnt;
    
    return 0;
}

/*
2 4 5 7 10 13
2 5 7

*/
Leave a Comment