Language: C++

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 2e9;
int n, plus_cnt, minus_cnt; 
ll K;
auto nC2 = [](ll a) { return a*(a-1)/2; };
vector<ll> Po,Ne;

ll calc_count(ll X, vector<ll> &V, vector<ll> &W, bool posi) {
  ll ret = 0ll;
  // t以上のものはWに何個あるかを求める
  rep(i, V.size()) {
    ll t = (X+V[i]-1)/V[i];
    int idx = lower_bound(ALL(W), t)-W.begin();
    if (posi && i>=idx) ret += W.size()-i-1; // 自分以下のものは含めない
    else ret+=W.size()-idx;
  }
  return ret;
} 

ll calc_negative() {
  ll ok = Po[0]*Ne[0];
  ll ng = Po[plus_cnt-1]*Ne[minus_cnt-1]+1;
  // 積がX以上の個数は何個あるかを2分探索
  while(ng-ok>1) {
    ll mid=(ok+ng)/2;
    ll r = calc_count(mid, Ne,Po, false);
    if (r<=K) ng = mid;
    else ok = mid;
  }
  return ok;
}

ll calc_positive() {
  ll ok = 1ll;
  ll ng = 1e18+1;
  while(ng-ok>1ll) {
    ll mid = (ok+ng)/2;
    ll r = calc_count(mid, Ne, Ne, true)+calc_count(mid,Po, Po, true);
    if (r<=nC2(n)-K) ng = mid;
    else ok = mid;
  }
  return ok;
}

int main() {
  INCANT;
  cin >> n >> K;
  ll a;
  rep(i, n) {
    cin >> a;
    if (a<0) Ne.push_back(-a); // 便宜上正にする
    else if (a>0) Po.push_back(a);
  }
  plus_cnt = Po.size();minus_cnt = Ne.size();
  sort(ALL(Ne)); sort(ALL(Po));
  if (minus_cnt*plus_cnt>=K) {
    cout << (-1)*calc_negative() << "\n";
  } else if (nC2(n)-nC2(plus_cnt)-nC2(minus_cnt) <=K) { // 正
    cout << calc_positive() << "\n";
  } else cout << 0 << "\n";
  return 0;
}#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 2e9;
int n, plus_cnt, minus_cnt; 
ll K;
auto nC2 = [](ll a) { return a*(a-1)/2; };
vector<ll> Po,Ne;

ll calc_count(ll X, vector<ll> &V, vector<ll> &W, bool posi) {
  ll ret = 0ll;
  // t以上のものはWに何個あるかを求める
  rep(i, V.size()) {
    ll t = (X+V[i]-1)/V[i];
    int idx = lower_bound(ALL(W), t)-W.begin();
    if (posi && i>=idx) ret += W.size()-i-1; // 自分以下のものは含めない
    else ret+=W.size()-idx;
  }
  return ret;
} 

ll calc_negative() {
  ll ok = Po[0]*Ne[0];
  ll ng = Po[plus_cnt-1]*Ne[minus_cnt-1]+1;
  // 積がX以上の個数は何個あるかを2分探索
  while(ng-ok>1) {
    ll mid=(ok+ng)/2;
    ll r = calc_count(mid, Ne,Po, false);
    if (r<=K) ng = mid;
    else ok = mid;
  }
  return ok;
}

ll calc_positive() {
  ll ok = 1ll;
  ll ng = 1e18+1;
  while(ng-ok>1ll) {
    ll mid = (ok+ng)/2;
    ll r = calc_count(mid, Ne, Ne, true)+calc_count(mid,Po, Po, true);
    if (r<=nC2(n)-K) ng = mid;
    else ok = mid;
  }
  return ok;
}

int main() {
  INCANT;
  cin >> n >> K;
  ll a;
  rep(i, n) {
    cin >> a;
    if (a<0) Ne.push_back(-a); // 便宜上正にする
    else if (a>0) Po.push_back(a);
  }
  plus_cnt = Po.size();minus_cnt = Ne.size();
  sort(ALL(Ne)); sort(ALL(Po));
  if (minus_cnt*plus_cnt>=K) {
    cout << (-1)*calc_negative() << "\n";
  } else if (nC2(n)-nC2(plus_cnt)-nC2(minus_cnt) <=K) { // 正
    cout << calc_positive() << "\n";
  } else cout << 0 << "\n";
  return 0;
}

Compiler output:
a.cc:78:2: error: stray '#' in program
   78 | }#include <algorithm>
      |  ^
a.cc:78:3: error: 'include' does not name a type
   78 | }#include <algorithm>
      |   ^~~~~~~
a.cc:95:11: error: redefinition of 'const int INF'
   95 | const int INF = 2e9;
      |           ^~~
a.cc:18:11: note: 'const int INF' previously defined here
   18 | const int INF = 2e9;
      |           ^~~
a.cc:96:5: error: redefinition of 'int n'
   96 | int n, plus_cnt, minus_cnt;
      |     ^
a.cc:19:5: note: 'int n' previously declared here
   19 | int n, plus_cnt, minus_cnt;
      |     ^
a.cc:96:8: error: redefinition of 'int plus_cnt'
   96 | int n, plus_cnt, minus_cnt;
      |        ^~~~~~~~
a.cc:19:8: note: 'int plus_cnt' previously declared here
   19 | int n, plus_cnt, minus_cnt;
      |        ^~~~~~~~
a.cc:96:18: error: redefinition of 'int minus_cnt'
   96 | int n, plus_cnt, minus_cnt;
      |                  ^~~~~~~~~
a.cc:19:18: note: 'int minus_cnt' previously declared here
   19 | int n, plus_cnt, minus_cnt;
      |                  ^~~~~~~~~
a.cc:97:4: error: redefinition of 'll K'
   97 | ll K;
      |    ^
a.cc:20:4: note: 'll K' previously declared here
   20 | ll K;
      |    ^
a.cc:98:6: error: conflicting declaration 'auto nC2'
   98 | auto nC2 = [](ll a) { return a*(a-1)/2; };
      |      ^~~
a.cc:21:6: note: previous declaration as '<lambda(ll)> nC2'
   21 | auto nC2 = [](ll a) { return a*(a-1)/2; };
      |      ^~~
a.cc:99:12: error: redefinition of 'std::vector<long long int> Po'
   99 | vector<ll> Po,Ne;
      |            ^~
a.cc:22:12: note: 'std::vector<long long int> Po' previously declared here
   22 | vector<ll> Po,Ne;
      |            ^~
a.cc:99:15: error: redefinition of 'std::vector<long long int> Ne'
   99 | vector<ll> Po,Ne;
      |               ^~
a.cc:22:15: note: 'std::vector<long long int> Ne' previously declared here
   22 | vector<ll> Po,Ne;
      |               ^~
a.cc:101:4: error: redefinition of 'll calc_count(ll, std::vector<long long int>&, std::vector<long long int>&, bool)'
  101 | ll calc_count(ll X, vector<ll> &V, vector<ll> &W, bool posi) {
      |    ^~~~~~~~~~
a.cc:24:4: note: 'll calc_count(ll, std::vector<long long int>&, std::vector<long long int>&, bool)' previously defined here
   24 | ll calc_count(ll X, vector<ll> &V, vector<ll> &W, bool posi) {
      |    ^~~~~~~~~~
a.cc:113:4: error: redefinition of 'll calc_negative()'
  113 | ll calc_negative() {
      |    ^~~~~~~~~~~~~
a.cc:36:4: note: 'll calc_negative()' previously defined here
   36 | ll calc_negative() {
      |    ^~~~~~~~~~~~~
a.cc:126:4: error: redefinition of 'll calc_positive()'
  126 | ll calc_positive() {
      |    ^~~~~~~~~~~~~
a.cc:49:4: note: 'll calc_positive()' previously defined here
   49 | ll calc_positive() {
      |    ^~~~~~~~~~~~~
a.cc:138:5: error: redefinition of 'int main()'
  138 | int main() {
      |     ^~~~
a.cc:61:5: note: 'int main()' previously defined here
   61 | int main() {
      |     ^~~~