GUPTA MECHANICAL

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

Saturday 3 December 2022

[Solution] Red Blue Flowers CodeChef Solution



Problem

Chef has a garden containing N cells. The i-th cell has R_i red flowers and B_i blue flowers. Chef can collect only one type of flowers (either red or blue) from each cell.

Let X denote the total number of red flowers Chef collects and Y denote the total number of blue flowers Chef collects. Chef wants to maximize the value of \mathrm{min}(X, Y). Can you help Chef?

Input Format

  • The first line contains a single integer T — the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer N — the number of cells in Chef's garden.
  • The second line of each test case contains N space-separated integers R_1, R_2, \dots, R_N denoting the number of red flowers in each cell.
  • The third line of each test case contains N space-separated integers B_1, B_2, \dots, B_N denoting the number of blue flowers in each cell.

Output Format

For each test case, output the maximum value of \mathrm{min}(X, Y).

Explanation:

Test case 1: If Chef collects 1 red flower from the cell, Chef will have a total of 1 red flower (X = 1) and 0 blue flowers (Y = 0).
If Chef collects the 101 blue flowers from the cell, Chef will have a total of 0 red flowers (X = 0) and 101 blue flowers (Y = 101).


Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇


Either way, \mathrm{min}(X, Y) = 0, the answer is 0.

Test case 2: Chef collects the 199 blue flowers from the first cell and the 200 red flowers from the second cell, so \mathrm{min}(X, Y) = 199, which is maximum.

Test case 3: Chef collects blue cells from the first three cells (Y = 3 + 1 + 3) and red flowers from the fourth cell (X = 10), so \mathrm{min}(X, Y) = 7, which is maximum.

No comments:

Post a Comment