This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h> // pA
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define debug(x) cerr << #x << " = " << (x) << ' '
#define endl cerr << '\n'
#define all(v) (v).begin(), (v).end()
#define lowbit(x) (x)&-(x)
#define pb emplace_back
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const int N = 3e5+5;
const int INF = 2e9;
ll n, Q;
pll p[N];
vector<ll> v;
inline bool chk(ll w)
{
ll i, cnt = 0, L=1;
for (i=1; i <= n; ++i)
{
while (p[i].F-p[L].F > w) ++L;
cnt += i - L;
}
return cnt >= Q;
}
int main(void)
{ IO
ll i, lb, mid, ub, j;
cin >> n >> Q;
for (i=1; i <= n; ++i) cin >> p[i].F >> p[i].S;
sort(p+1, p+n+1);
lb = 1, ub = 1e18;
while (lb < ub)
{
mid = (lb+ub)>>1;
if (chk(mid)) ub = mid;
else lb = mid+1;
}
for (i=1; i <= n; ++i)
{
for (j=i-1; j >= 1; --j)
{
if (p[i].F-p[j].F > lb) break;
v.pb(p[i].F-p[j].F);
}
}
sort(all(v));
for (i=0; i < Q; ++i) cout << v[i] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |