#include<bits/stdc++.h>
#define int long long
using namespace std;
using pii=pair<pair<int,int>,pair<int,int>>;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k,num=1;
cin>>n>>k;
map<int,pii>m;
vector<pii>v(n);
for(int i=0;i<n;i++)cin>>v[i].first.first>>v[i].second.first>>v[i].first.second>>v[i].second.second;
sort(v.begin(),v.end());
m[1]=v[0];
for(int i=1;i<n;i++)
{
pii x=v[i];
bool b=0;
for(int j=1;j<=num;j++)
{
if(x.first.first<=m[j].first.first&&x.first.second>=m[j].first.second)
{
if(x.second.first<=m[j].second.first&&x.second.second>=m[j].second.second){b=1;break;}
if(x.second.first>=m[j].second.first&&x.second.first<=m[j].second.second){m[j].second.first=x.second.first;b=1;}
if(x.second.second>=m[j].second.first&&x.second.second<=m[j].second.second){m[j].second.second=x.second.second;b=1;}
}
if(x.first.first>=m[j].first.first&&x.first.first<=m[j].first.second)
{
if(x.second.first<=m[j].second.first&&x.second.second>=m[j].second.second){m[j].first.first=x.first.first;b=1;break;}
if(x.second.first>=m[j].second.first&&x.second.first<=m[j].second.second){m[j].first.first=x.first.first;m[j].second.first=x.second.first;b=1;}
if(x.second.second>=m[j].second.first&&x.second.second<=m[j].second.second){m[j].first.first=x.first.first;m[j].second.second=x.second.second;b=1;}
}
if(x.first.second>=m[j].first.first&&x.first.second<=m[j].first.second)
{
if(x.second.first<=m[j].second.first&&x.second.second>=m[j].second.second){m[j].first.second=x.first.second;b=1;break;}
if(x.second.first>=m[j].second.first&&x.second.first<=m[j].second.second){m[j].first.second=x.first.second;m[j].second.first=x.second.first;b=1;}
if(x.second.second>=m[j].second.first&&x.second.second<=m[j].second.second){m[j].first.second=x.first.second;m[j].second.second=x.second.second;b=1;}
}
if(b)break;
}
if(!b)
{
num++;
m[num]=x;
}
}
for(int i=1;i<=min(num,k);i++)
{
cout<<m[i].first.first<<" "<<m[i].second.first<<'\n';
}
for(int i=k-num;i>0;i--)cout<<m[1].first.first<<" "<<m[1].second.first<<'\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |