MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/TurnTheRectangles/solution.cpp:9–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace std;
8
9int main() {
10 int n;
11 cin>>n;
12 int a[n][2];
13 int s[n];
14 int flag=0;
15 for(int i=0;i<n;i++)
16 cin>>a[i][0]>>a[i][1]; //Taking Inputs
17 s[0]=max(a[0][0],a[0][1]); //We want a greedy approach. Thus, we use the greatest dimension of the first rectangle.
18 for(int i=1;i<n;i++)
19 {
20 if(max(a[i][0],a[i][1])<=s[i-1]) s[i]=max(a[i][0],a[i][1]); //Then we check if either of the two dimensions are smaller than the previous height.
21 else if(min(a[i][0],a[i][1])<=s[i-1]) s[i]=min(a[i][0],a[i][1]); //IF both are smaller we choose the larger of the two smaller.
22 else
23 {
24 flag=1;
25 break; //If none are smaller we dont need to loop further, we can break here.
26 }
27 }
28
29 if(flag==0) cout<<"YES"<<endl;
30 else cout<<"NO"<<endl;
31
32 return 0;
33}

Callers

nothing calls this directly

Calls 2

maxFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected