#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
int t;
int n;
struct node{
int x,y,tx,ty;
}a[N];
bool cmp(node p1,node p2)
{
if(p1.x==p2.x)
{
return p1.y<p2.y;
}
return p1.x<p2.x;
}
bool cp(node p1,node p2)
{
if(p1.y==p2.y)
{
return p1.x<p2.x;
}
return p1.y<p2.y;
}
int mix,miy;
int nowx,nowy;
queue<node> q;
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y>>a[i].tx>>a[i].ty;
}
sort(a+1,a+1+n,cmp);
mix=a[1].x;
nowx=mix+a[1].tx;
for(int i=2;i<=n;i++)
{
if(nowx<a[i].x)
{
mix+=a[i].x-nowx;
nowx=a[i].x;
}
nowx+=a[i].tx;
}
sort(a+1,a+1+n,cp);
nowx=mix;
nowy=0;
miy=0;
for(int i=1;i<=n;i++)
{
q.push(a[i]);
}
while(!q.empty())
{
node p=q.front();
q.pop();
if(nowx<p.x)
{
q.push(p);
continue;
}
if(nowy<p.y)
{
miy+=p.y-nowy;
nowy=p.y;
}
nowx+=p.tx;
nowy+=p.ty;
}
cout<<mix<<" "<<miy;
return 0;
}
思路是先保证力量最小,然后依靠力量最小去找精神最小,求调。