This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 3e5 + 10;
int n, k;
ll x[maxn], y[maxn], bef[maxn], nxt[maxn];
struct element
{
int idx;
ll sum;
bool operator < (const element &e) const
{
return sum > e.sum;
}
};
void solve()
{
cin >> n >> k;
bool y0 = true;
for (int i = 1; i <= n; i ++)
{
cin >> x[i] >> y[i];
if (y[i] != 0)
y0 = false;
}
if (n <= 1000)
{
vector < ll > v;
for (int i = 1; i <= n; i ++)
for (int j = i + 1; j <= n; j ++)
{
v.push_back(abs(x[i] - x[j]) + abs(y[i] - y[j]));
}
sort(v.begin(), v.end());
for (int i = 0; i < k; i ++)
cout << v[i] << endl;
}
else
if (y0 == true)
{
sort(x + 1, x + n + 1);
priority_queue < element > pq;
for (int i = 1; i <= n; i ++)
{
bef[i] = i - 1;
if (i != 1)
{
element e;
e.sum = x[i] - x[i - 1];
e.idx = i;
pq.push(e);
}
}
for (int q = 0; q < k; q ++)
{
element e = pq.top();
pq.pop();
cout << e.sum << endl;
bef[e.idx] --;
if (bef[e.idx] != 0)
{
e.sum = x[e.idx] - x[bef[e.idx]];
pq.push(e);
}
}
}
}
int main()
{
solve();
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... |