Submission #10203776


Source Code Expand

Copy
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 2 * (i64)1e5 + 1000;
i64 n, k, a[maxn];
vi pot;
vi neg;
vi zero;

bool chk(i64 p) {
    i64 c = 0;
    for (i64 x : neg) {
        if (p == 0) c += n - int(neg.size());
        else if (p > 0) {
            i64 b = -(p / (-x));
            c += n - (lower_bound(all(neg), b) - neg.begin());
        } else {
            i64 b = (-p - x - 1) / (-x);
            c += pot.end() - lower_bound(all(pot), b);
        }
    }
    if (p >= 0) c += n * int(zero.size());
    for (i64 x : pot) {
        if (p == 0) c += n - int(pot.size());
        else if (p > 0) {
            i64 b = p / x;
            c += int(neg.size()) + int(zero.size()) + (upper_bound(all(pot), b) - pot.begin());
        } else if (p < 0) {
            i64 b = -((-p + x - 1) / x);
            c += upper_bound(all(neg), b) - neg.begin();
        }
    }
    forn(i, n) if (a[i] * a[i] <= p) c--;
    c /= 2;
    if (c >= k) return true;
    else return false;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif

	cin >> n >> k;
	forn(i, n) {
        cin >> a[i];
        if (a[i] > 0) pot.eb(a[i]);
        else if (a[i] == 0) zero.eb(a[i]);
        else if (a[i] < 0) neg.eb(a[i]);
	}
	sort(all(pot));
	sort(all(zero));
	sort(all(neg));
	i64 l = -(i64)1e18, r = (i64)1e18, ans = -1;
	while (l <= r) {
        i64 mid = (r - l) / 2 + l;
     //   cerr << l << " " << r << " " << mid << endl;
        if (chk(mid)) {
            r = mid - 1;
            ans = mid;
        } else {
            l = mid + 1;
        }
	}
	cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Submission Info

Submission Time
Task D - Pairs
User maxzzy8
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2892 Byte
Status AC
Exec Time 561 ms
Memory 2804 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 79
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_small_01.txt, sub1_small_02.txt, sub1_small_03.txt, sub1_small_04.txt, sub1_small_05.txt, sub1_small_06.txt, sub1_small_07.txt, sub1_small_08.txt, sub1_small_09.txt, sub1_small_10.txt, sub1_small_11.txt, sub1_small_12.txt, sub1_small_13.txt, sub1_small_14.txt, sub1_small_15.txt, sub1_small_16.txt, sub1_small_17.txt, sub1_small_18.txt, sub1_small_19.txt, sub1_small_20.txt, sub1_small_21.txt, sub1_small_22.txt, sub1_small_23.txt, sub1_small_24.txt, sub1_small_25.txt, sub1_small_26.txt, sub1_small_27.txt, sub1_small_28.txt, sub1_small_29.txt, sub1_small_30.txt, sub1_small_31.txt, sub1_small_32.txt, sub1_small_33.txt, sub1_small_34.txt, sub1_small_35.txt, sub1_small_36.txt, sub1_small_37.txt, sub1_small_38.txt, sub1_small_39.txt, sub1_small_40.txt, sub1_small_41.txt, sub1_small_42.txt, sub1_small_43.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sub1_01.txt AC 168 ms 1408 KB
sub1_02.txt AC 367 ms 2016 KB
sub1_03.txt AC 520 ms 2676 KB
sub1_04.txt AC 238 ms 1912 KB
sub1_05.txt AC 178 ms 1404 KB
sub1_06.txt AC 64 ms 768 KB
sub1_07.txt AC 425 ms 2400 KB
sub1_08.txt AC 494 ms 2404 KB
sub1_09.txt AC 390 ms 2020 KB
sub1_10.txt AC 82 ms 768 KB
sub1_11.txt AC 338 ms 2548 KB
sub1_12.txt AC 49 ms 640 KB
sub1_13.txt AC 315 ms 2320 KB
sub1_14.txt AC 139 ms 1152 KB
sub1_15.txt AC 51 ms 640 KB
sub1_16.txt AC 384 ms 2428 KB
sub1_17.txt AC 195 ms 1508 KB
sub1_18.txt AC 21 ms 384 KB
sub1_19.txt AC 372 ms 2676 KB
sub1_20.txt AC 260 ms 1656 KB
sub1_21.txt AC 384 ms 2676 KB
sub1_22.txt AC 245 ms 1532 KB
sub1_23.txt AC 256 ms 1532 KB
sub1_24.txt AC 195 ms 1532 KB
sub1_25.txt AC 100 ms 896 KB
sub1_26.txt AC 379 ms 2252 KB
sub1_27.txt AC 28 ms 2676 KB
sub1_28.txt AC 544 ms 2804 KB
sub1_29.txt AC 448 ms 2804 KB
sub1_30.txt AC 538 ms 2664 KB
sub1_31.txt AC 536 ms 2700 KB
sub1_32.txt AC 533 ms 2652 KB
sub1_33.txt AC 561 ms 2696 KB
sub1_small_01.txt AC 3 ms 256 KB
sub1_small_02.txt AC 2 ms 256 KB
sub1_small_03.txt AC 4 ms 256 KB
sub1_small_04.txt AC 2 ms 256 KB
sub1_small_05.txt AC 2 ms 256 KB
sub1_small_06.txt AC 4 ms 256 KB
sub1_small_07.txt AC 2 ms 256 KB
sub1_small_08.txt AC 3 ms 256 KB
sub1_small_09.txt AC 2 ms 256 KB
sub1_small_10.txt AC 3 ms 256 KB
sub1_small_11.txt AC 3 ms 256 KB
sub1_small_12.txt AC 4 ms 256 KB
sub1_small_13.txt AC 2 ms 256 KB
sub1_small_14.txt AC 4 ms 256 KB
sub1_small_15.txt AC 1 ms 256 KB
sub1_small_16.txt AC 5 ms 256 KB
sub1_small_17.txt AC 2 ms 256 KB
sub1_small_18.txt AC 1 ms 256 KB
sub1_small_19.txt AC 1 ms 256 KB
sub1_small_20.txt AC 4 ms 256 KB
sub1_small_21.txt AC 4 ms 256 KB
sub1_small_22.txt AC 4 ms 256 KB
sub1_small_23.txt AC 1 ms 256 KB
sub1_small_24.txt AC 1 ms 256 KB
sub1_small_25.txt AC 2 ms 256 KB
sub1_small_26.txt AC 2 ms 256 KB
sub1_small_27.txt AC 3 ms 256 KB
sub1_small_28.txt AC 2 ms 256 KB
sub1_small_29.txt AC 3 ms 256 KB
sub1_small_30.txt AC 2 ms 256 KB
sub1_small_31.txt AC 5 ms 256 KB
sub1_small_32.txt AC 3 ms 256 KB
sub1_small_33.txt AC 2 ms 256 KB
sub1_small_34.txt AC 2 ms 256 KB
sub1_small_35.txt AC 5 ms 256 KB
sub1_small_36.txt AC 1 ms 256 KB
sub1_small_37.txt AC 4 ms 256 KB
sub1_small_38.txt AC 2 ms 256 KB
sub1_small_39.txt AC 2 ms 256 KB
sub1_small_40.txt AC 6 ms 256 KB
sub1_small_41.txt AC 1 ms 256 KB
sub1_small_42.txt AC 1 ms 256 KB
sub1_small_43.txt AC 1 ms 256 KB