2 solutions

  • 0
    @ 2022-4-3 1:04:23
    #include<bits/stdc++.h>
    using namespace std;
    int n, x, a[1000010],sum=0;
    int main(){
    	cin >> n;
    	for(int i = 0;i < n; i++){
    		cin >> a[i];
    	}
    	cin >> x;
    	sort(a, a + n);
    	for(int i = 0;i < n; i++){
    		int idx = lower_bound(a, a + n, x - a[i]) - a;
    		if(a[idx] == x - a[i]) sum++;
    	}
    	cout << sum / 2;
    	return 0;
    }
    

    Information

    ID
    1102
    Time
    1000ms
    Memory
    20MiB
    Difficulty
    6
    Tags
    # Submissions
    76
    Accepted
    21
    Uploaded By