Advertisement
YEZAELP

CUBE-087: Finding Jedi

Jul 11th, 2020
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long ar[1000001];
  5.  
  6. int main(){
  7.  
  8.     int n;
  9.     long long k;
  10.     scanf("%d%lld",&n,&k);
  11.     for(int i=1;i<=n;i++) {
  12.         int x;
  13.         scanf("%d",&x);
  14.         ar[x]++;
  15.     }
  16.  
  17.     long long ans=0;
  18.     for(int i=0;i<=1000000;i++){
  19.         int x=i,y=k-x;
  20.         if(ar[x] < 1 or ar[y] < 1) continue;
  21.         if(x == y){
  22.             ans += (long long)(ar[x]*(ar[x]-1))/2;
  23.             ar[x] = 0;
  24.         }
  25.         else {
  26.             ans += ar[x]*ar[y];
  27.             ar[x] = 0;
  28.             ar[y] = 0;
  29.         }
  30.     }
  31.  
  32.     printf("%lld",ans);
  33.  
  34.     return 0;
  35.  
  36. }
Advertisement
RAW Paste Data Copied
Advertisement