#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define INF 1000000000000000000
bool cmp(pair<int, int> a, pair<int, int> b) {
if(a.second != b.second) return a.second < b.second;
else return a.first < b.first;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
pair<int, int> a[n];
for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
if(k == 1) {
int u = -INF, d = INF, l = INF, r = -INF;
for(int i = 0; i < n; i++) {
u = max(u, a[i].second);
d = min(d, a[i].second);
r = max(r, a[i].first);
l = min(l, a[i].first);
}
cout << l << " " << d << " " << max(u-d, r-l) << '\n';
} else if(k == 2) {
sort(a, a+n);
int u[n], d[n], l[n], r[n], mn = INF, x1, y1, x2, y2, ans1, ans2;
u[0] = d[0] = a[0].second;
l[0] = r[0] = a[0].first;
int u2[n], d2[n], l2[n], r2[n];
u2[n-1] = d2[n-1] = a[n-1].second;
l2[n-1] = r2[n-1] = a[n-1].first;
for(int i = 1; i < n; i++) {
u[i] = max(u[i-1], a[i].second);
d[i] = min(d[i-1], a[i].second);
r[i] = max(r[i-1], a[i].first);
l[i] = min(l[i-1], a[i].first);
}
for(int i = n-2; i >= 0; i--) {
u2[i] = max(u2[i+1], a[i].second);
d2[i] = min(d2[i+1], a[i].second);
r2[i] = max(r2[i+1], a[i].first);
l2[i] = min(l2[i+1], a[i].first);
}
for(int i = 0; i < n-1; i++) {
int len1 = max(u[i]-d[i], r[i]-l[i]);
int len2 = max(u2[i+1]-d2[i+1], r2[i+1]-l2[i+1]);
if(max(len1, len2) < mn) {
if(a[i].first != a[i+1].first) {
mn = max(len1, len2);
x1 = l[i]-(len1-(r[i]-l[i])); y1 = d[i];
x2 = l2[i+1]; y2 = d2[i+1];
ans1 = len1; ans2 = len2;
} else {
if(u[i] < d2[i+1]) {
mn = max(len1, len2);
x1 = l[i]; y1 = d[i]-(len1-(u[i]-d[i]));
x2 = l2[i+1]; y2 = d2[i+1];
ans1 = len1; ans2 = len2;
} else if(u2[i+1] < d[i]) {
mn = max(len1, len2);
x1 = l[i]; y1 = d[i];
x2 = l2[i+1]; y2 = d2[i+1]-(len2-(u2[i+1]-d2[i+1]));
ans1 = len1; ans2 = len2;
}
}
}
}
sort(a, a+n, cmp);
u[0] = d[0] = a[0].second;
l[0] = r[0] = a[0].first;
u2[n-1] = d2[n-1] = a[n-1].second;
l2[n-1] = r2[n-1] = a[n-1].first;
for(int i = 1; i < n; i++) {
u[i] = max(u[i-1], a[i].second);
d[i] = min(d[i-1], a[i].second);
r[i] = max(r[i-1], a[i].first);
l[i] = min(l[i-1], a[i].first);
}
for(int i = n-2; i >= 0; i--) {
u2[i] = max(u2[i+1], a[i].second);
d2[i] = min(d2[i+1], a[i].second);
r2[i] = max(r2[i+1], a[i].first);
l2[i] = min(l2[i+1], a[i].first);
}
for(int i = 0; i < n-1; i++) {
int len1 = max(u[i]-d[i], r[i]-l[i]);
int len2 = max(u2[i+1]-d2[i+1], r2[i+1]-l2[i+1]);
if(max(len1, len2) < mn) {
if(a[i].second != a[i+1].second) {
mn = max(len1, len2);
x1 = l[i]; y1 = d[i]-(len1-(u[i]-d[i]));
x2 = l2[i+1]; y2 = d2[i+1];
ans1 = len1; ans2 = len2;
} else {
if(r[i] < l2[i+1]) {
mn = max(len1, len2);
x1 = l[i]-(len1-(r[i]-l[i])); y1 = d[i];
x2 = l2[i+1]; y2 = d2[i+1];
ans1 = len1; ans2 = len2;
} else if(r2[i+1] <l[i]) {
mn = max(len1, len2);
x1 = l[i]; y1 = d[i];
x2 = l2[i+1]-(len2-(r2[i+1]-l2[i+1])); y2 = d2[i+1];
ans1 = len1; ans2 = len2;
}
}
}
}
cout << x1 << " " << y1 << " " << ans1 << '\n';
cout << x2 << " " << y2 << " " << ans2 << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Integer 0 violates the range [1, 2*10^9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Integer 519691042940 violates the range [-3*10^9, 3*10^9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |