/*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
//~ typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const ll mod = 1e9+7;
ll mode(ll a) {
while (a < 0) {
a += mod;
}
return a % mod;
}
ll subt(ll a, ll b) {
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b) {
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b) {
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int main() {
do_not_disturb
int n, k;
cin >> n >> k;
vector <pll> pos(n);
for (int i = 0; i < n; i++) {
cin >> pos[i].first >> pos[i].second;
}
sort(all(pos));
vector <ll> Xs;
map <ll, vector <ll>> byX;
for (auto to : pos) {
if (sz(Xs) == 0 || Xs.back() != to.first) {
Xs.pb(to.first);
}
byX[to.first].pb(to.second);
}
multiset <ll, greater <ll>> st;
for (int i = 0; i < sz(Xs); i++) {
auto x1 = Xs[i], x2 = (i < sz(Xs)-1 ? Xs[i+1] : 0);
for (int j = 0; j < sz(byX[x1])-1; j++) {
st.insert(abs(byX[x1][j]-byX[x1][j+1]));
if (sz(st) > k) {
st.erase(st.find(*st.begin()));
}
}
if (i < sz(Xs)-1) {
for (int j = 0; j < sz(byX[x1]); j++) {
auto it = lb(all(byX[x2]), byX[x1][j]);
if (it != byX[x2].end()) {
st.insert(abs(byX[x1][j]-(*it))+x2-x1);
if (sz(st) > k) {
st.erase(st.find(*st.begin()));
}
}
if (it != byX[x2].begin()) {
it--;
st.insert(abs(byX[x1][j]-(*it))+x2-x1);
if (sz(st) > k) {
st.erase(st.find(*st.begin()));
}
}
}
}
}
auto it = st.end();
it--;
for (; it != st.begin(); it--) {
cout << *it << endl;
}
cout << *it << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
649 ms |
46612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
424 ms |
33540 KB |
Output is correct |
2 |
Correct |
393 ms |
33512 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
387 ms |
33500 KB |
Output is correct |
5 |
Correct |
184 ms |
6212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
424 ms |
33540 KB |
Output is correct |
2 |
Correct |
393 ms |
33512 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
387 ms |
33500 KB |
Output is correct |
5 |
Correct |
184 ms |
6212 KB |
Output is correct |
6 |
Incorrect |
386 ms |
33516 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |