#K94227. Maximum Combined Flower Beauty

    ID: 38595 Type: Default 1000ms 256MiB

Maximum Combined Flower Beauty

Maximum Combined Flower Beauty

You are given a garden with n flowers. Each flower is characterized by two integers: its type and its beauty.

A pair of flowers (i, j) is called visually pleasing if and only if both of the following conditions are met:

  • The type of the first flower is strictly less than the type of the second flower, i.e. \(t_i < t_j\).
  • The beauty of the first flower is strictly less than the beauty of the second, i.e. \(b_i < b_j\).

Your task is to determine the maximum combined beauty value of any visually pleasing pair of flowers in the garden. The combined beauty of a pair is the sum of their beauty values. If no such pair exists, output -1.

Note: All comparisons are strict.

inputFormat

The first line of input contains a single integer \(n\) \( (1 \leq n \leq 10^5) \), representing the number of flowers.

Each of the following \(n\) lines contains two space-separated integers \(t_i\) and \(b_i\) \( (1 \leq t_i, b_i \leq 10^9) \), representing the type and beauty of the \(i\)-th flower respectively.

Input is provided via standard input (stdin).

outputFormat

Output a single integer representing the maximum combined beauty value of any visually pleasing pair of flowers. If no such pair exists, output -1.

The output should be written to standard output (stdout).

## sample
5
1 2
2 4
3 1
4 3
5 5
9