There are
n
rectangles in a row. You can either turn each rectangle by
90
degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.
Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).
Input
The first line contains a single integer
n
(
1
≤
n
≤
10
5
) — the number of rectangles.
Each of the next
n
lines contains two integers
w
i
and
h
i
(
1
≤
w
i
,
h
i
≤
10
9
) — the width and the height of the
i
-th rectangle.
Output
Print “YES” (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print “NO”.
You can print each letter in any case (upper or lower).
Examples
inputCopy
3
3 4
4 6
3 5
outputCopy
YES
inputCopy
2
3 4
5 5
outputCopy
NO
Note
In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].
In the second test, there is no way the second rectangle will be not higher than the first one.
自然想到贪心:
肯定是上界尽可能大,这样才能保证剩下的有可能比 previous 小,如果比 width && height 都小,自然就不可能了:
#include
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define maxn 200005
const int mod=1e9+7;
#define eps 1e-5
#define pi acos(-1.0)
ll quickpow(ll a,ll b)
{
ll ans=1;
while(b){
if(b&1){
ans=ans*a;
}
a=a*a;
b>>=1;
}
return ans;
}
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
struct rec
{
int width,height;
}recc[maxn];
int main()
{
ios::sync_with_stdio(false);
int n;
cin>>n;
int flag=0;
for(int i=0;i>recc[i].width>>recc[i].height;
}
int tmp=max(recc[0].width,recc[0].height);
for(int i=1;itmp&&res2
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net