#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(x) cout << #x << " " << x << endl;
#define pii pair<int, int>
const int inf = 1e9 + 10;
void solve1( vector<pii>& v ){
int x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;
for( auto [x, y] : v ){
x1 = min( x1, x );
x2 = max( x2, x );
y1 = min( y1, y );
y2 = max( y2, y );
}
int tam = max( x2 - x1, y2 - y1 );
cout << x1 << " " << y1 << " " << tam << endl;
}
struct rect{
int x, y, tam; rect( int x = 0, int y = 0, int tam = 0 ) :x(x), y(y), tam(tam) {}
};
void solve2( vector<pii>& v ){
sort( v.begin(), v.end(), [&]( pii a, pii b ){
return a.first < b.first;
}); // ordena por x;
vector<rect> resp( v.size() );
int x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;
for( int i = 0; i < v.size(); i++ ){
auto [x, y] = v[i];
x1 = min( x1, x );
x2 = max( x2, x );
y1 = min( y1, y );
y2 = max( y2, y );
resp[i] = rect( x1, y1, max( x2 - x1, y2 - y1 ) );
}
x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;
rect a( 0,0, inf ), b( 0, 0, inf );
for( int i = v.size() - 1; i > 0; i-- ){
auto [x, y] = v[i];
x1 = min( x1, x );
x2 = max( x2, x );
y1 = min( y1, y );
y2 = max( y2, y );
rect cur( x1, y1, max( x2 - x1, y2 - y1 ) );
if( max( cur.tam, resp[i - 1].tam ) < max( a.tam, b.tam ) ){
a = cur;
b = resp[i - 1];
}
}
sort( v.begin(), v.end(), [&]( pii a, pii b ){
return a.second < b.second;
}); // ordena por y;
resp.clear();
resp.resize(v.size());
x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;
for( int i = 0; i < v.size(); i++ ){
auto [x, y] = v[i];
x1 = min( x1, x );
x2 = max( x2, x );
y1 = min( y1, y );
y2 = max( y2, y );
resp[i] = rect( x1, y1, max( x2 - x1, y2 - y1 ) );
}
x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;
for( int i = v.size() - 1; i > 0; i-- ){
auto [x, y] = v[i];
x1 = min( x1, x );
x2 = max( x2, x );
y1 = min( y1, y );
y2 = max( y2, y );
rect cur( x1, y1, max( x2 - x1, y2 - y1 ) );
if( max( cur.tam, resp[i - 1].tam ) < max( a.tam, b.tam ) ){
a = cur;
b = resp[i - 1];
}
}
cout << a.x << " " << a.y << " " << a.tam << endl;
cout << b.x << " " << b.y << " " << b.tam << endl;
}
int main(){
int n, k; cin >> n >> k;
vector<pii> v(n);
for( int i = 0; i < n; i++ ) cin >> v[i].first >> v[i].second;
if( k == 1 ) solve1(v);
else if( k == 2 ) solve2( v );
}
Compilation message
izvanzemaljci.cpp: In function 'void solve2(std::vector<std::pair<int, int> >&)':
izvanzemaljci.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for( int i = 0; i < v.size(); i++ ){
| ~~^~~~~~~~~~
izvanzemaljci.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for( int i = 0; i < v.size(); i++ ){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Integer 0 violates the range [1, 2*10^9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
352 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |