Skip to main content
Back to problems
Codeforces
Easy
Greedy
Sorting
Arrays
Laptops

Choose the most expensive laptop whose price is strictly less than its quality.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

You are given nn laptops. Each laptop has two attributes: price and quality.

Find whether there exists a pair of laptops such that one laptop is cheaper than another but also has higher quality. If such a pair exists, print "Happy Alex". Otherwise, print "Poor Alex".

In other words, Alex is happy if there is at least one inversion between price and quality: a laptop with smaller price and larger quality than some other laptop.

Intuition

The task is to detect whether the ordering by price is consistent with the ordering by quality. If any cheaper laptop is better in quality than a more expensive one, the answer is affirmative.

Input Format

  • The first line contains an integer nn.
  • Each of the next nn lines contains two integers pip_i and qiq_i describing the price and quality of the ii-th laptop.

Output Format

Print:

  • Happy Alex if there exists a pair of laptops where the cheaper one has higher quality.
  • Poor Alex otherwise.

Constraints

  • 1n1051 \le n \le 10^5
  • 1pi,qi1091 \le p_i, q_i \le 10^9
  • Prices may repeat.
  • Each laptop is described by exactly one price-quality pair.
Examples
Sample cases returned by the problem API.

Example 1

Input

3
100 10
200 5
150 7

Output

Happy Alex

Explanation

The laptop priced at 100 has quality 10, while the laptop priced at 200 has quality 5. A cheaper laptop has higher quality, so Alex is happy.

Example 2

Input

3
100 5
150 7
200 10

Output

Poor Alex

Explanation

Quality increases with price, so there is no cheaper laptop with higher quality than a more expensive one.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.