策策学长找py
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n,m,k,x,y;
cin>>t;
while(t--){
cin>>n>>m>>k;
vector<pair<int,int> > v;
while(k--){
cin>>x>>y;
v.push_back({x,y});
}
sort(v.begin(), v.end(), [](const pair<int, int> &x, const pair<int, int> &y) -> bool{
if(x.first+x.second!=y.first+y.second)
return x.first+x.second < y.first+y.second;
if(x.first!=y.first) return x.first<y.first;
return x.second<y.second;
});
int p=0,f=0;
for(int i=0;i<v.size()-1;i++)
if(v[i].first>v[i+1].first||v[i].second>v[i+1].second){
f=1;
break;
}
if(f) puts("NO");
else puts("YES");
}
}
#include<bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int> x,pair<int,int> y){
if(x.first+x.second!=y.first+y.second) return x.first+x.second < y.first+y.second;
if(x.first!=y.first) return x.first<y.first;
return x.second<y.second;
}
int main(){
int t,n,m,k,x,y;
cin>>t;
while(t--){
cin>>n>>m>>k;
vector<pair<int,int> > v;
while(k--){
cin>>x>>y;
v.push_back({x,y});
}
sort(v.begin(), v.end(),cmp);
int f=0;
for(int i=0;i<v.size()-1;i++)
if(v[i].first>v[i+1].first||v[i].second>v[i+1].second){
f=1;
break;
}
if(f) puts("NO");
else puts("YES");
}
}