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>
using namespace std;
using lint = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<lint> X(N), Y(N);
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
}
const auto Solve = [&](const auto &self, lint L, int k, vector<int> dead) -> pair<bool, vector<pair<int, int>>> {
if (count(begin(dead), end(dead), 1) == N) {
return {true, vector<pair<int, int>>(k, {0, 0})};
}
if (k == 0) {
return {false, vector<pair<int, int>>()};
}
lint minX = +2e9;
lint maxX = -2e9;
lint minY = +2e9;
lint maxY = -2e9;
for (int i = 0; i < N; i++) if (!dead[i]) {
minX = min(minX, X[i]);
maxX = max(maxX, X[i]);
minY = min(minY, Y[i]);
maxY = max(maxY, Y[i]);
}
for (auto x : {minX, maxX - L}) {
for (auto y : {minY, maxY - L}) {
vector<int> newDead = dead;
for (int i = 0; i < N; i++) if (!dead[i]) {
if (x <= X[i] && X[i] <= x + L && y <= Y[i] && Y[i] <= y + L) {
newDead[i] = 1;
}
}
auto res = self(self, L, k - 1, newDead);
if (res.first) {
res.second.emplace_back(x, y);
return res;
}
}
}
return {false, vector<pair<int, int>>()};
};
lint lo = 1, hi = 2e9;
while (lo < hi) {
lint md = (lo + hi) / 2;
if (Solve(Solve, md, K, vector<int>(N, 0)).first) {
hi = md;
} else {
lo = md + 1;
}
}
auto ans = Solve(Solve, lo, K, vector<int>(N, 0)).second;
for (int i = 0; i < K; i++) {
cout << ans[i].first << ' ' << ans[i].second << ' ' << lo << '\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... |