Header Ad

HackerEarth Pop-Up Orientation problem solution

In this HackerEarth Pop-Up Orientation problem solution In web application development, it is often required to draw a pop-up window on top of a web page when the user clicks on an icon on the page that brings up the pop-up.

You are given a web page with width x and height y, a pop-up window with width l and height m, and an icon at a distance a from the left of the page and distance b from the bottom of the page.
Your program should output the orientation in which the pop-up can be rendered fully, relative to the icon, within the page dimensions. The orientation of the pop-up should be such that it lies completely within the page.

There are 4 possible orientations: bottom-right, bottom-left, top-right, and top-left, in the same order of preference. In other words, you should first attempt to render the pop-up bottom-right, and if that is not possible, try bottom-left, and so on.

HackerEarth Pop-Up Orientation problem solution

HackerEarth Pop-Up Orientation problem solution.

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define REP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define REPI(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define pi 3.141592653589793

using namespace std;

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T mod(T x) { if(x < 0) return -x; else return x; }

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII > PPII;
typedef vector< PII > VPII;
typedef vector< PPII > VPPI;

const int MOD = 1e9 + 7;
const int INF = 1e9;

int main(int argc, char* argv[]) {
if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
if(argc == 3) freopen(argv[2], "w", stdout);
int t, x, y, l, m, a, b;
cin >> t;
REP(i, 0, t, 1) {
cin >> x >> y >> l >> m >> a >> b;
if (m <= b) {
if (l <= (x - a)) cout << "bottom-right" << endl;
else cout << "bottom-left" << endl;
else {
if (l <= (x - a)) cout << "top-right" << endl;
else cout << "top-left" << endl;


return 0;

Post a Comment