GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 13 May 2022

[Solution] Minimums and Maximums Codeforces Solution | Codeforces Problem Solution 2022

A. Minimums and Maximums
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

An array is beautiful if both of the following two conditions meet:

  • there are at least l1 and at most r1 elements in the array equal to its minimum;
  • there are at least l2 and at most r2 elements in the array equal to its maximum.

For example, the array [2,3,2,4,4,3,2] has 3 elements equal to its minimum (1-st, 3-rd and 7-th) and 2 elements equal to its maximum (4-th and 5-th).

Solution Click Below:-  CLICK HERE

Another example: the array [42,42,42] has 3 elements equal to its minimum and 3 elements equal to its maximum.

Your task is to calculate the minimum possible number of elements in a beautiful array.

Input

The first line contains one integer t (1t5000) — the number of test cases.

Each test case consists of one line containing four integers l1r1l2 and r2 (1l1r1501l2r250).

Output

For each test case, print one integer — the minimum possible number of elements in a beautiful array.

No comments:

Post a Comment