GUPTA MECHANICAL

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

Sunday, 8 May 2022

Tokitsukaze and Two Colorful Tapes Codeforces Solution | Codeforces Problem Solution 2022

E. Tokitsukaze and Two Colorful Tapes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Tokitsukaze has two colorful tapes. There are n distinct colors, numbered 1 through n, and each color appears exactly once on each of the two tapes. Denote the color of the i-th position of the first tape as cai, and the color of the i-th position of the second tape as cbi.

Solution Click Below:-  CLICK HERE

Now Tokitsukaze wants to select each color an integer value from 1 to n, distinct for all the colors. After that she will put down the color values in each colored position on the tapes. Denote the number of the i-th position of the first tape as numai, and the number of the i-th position of the second tape as numbi.

For example, for the above picture, assuming that the color red has value x (1xn), it appears at the 1-st position of the first tape and the 3-rd position of the second tape, so numa1=numb3=x.

[Solution] Tokitsukaze and Good 01-String

Tokitsukaze and Two Colorful Tapes Codeforces Solution

Tokitsukaze and Permutations Codeforces Solution

Note that each color i from 1 to n should have a distinct value, and the same color which appears in both tapes has the same value.

After labeling each color, the beauty of the two tapes is calculated as

i=1n|numainumbi|.

Please help Tokitsukaze to find the highest possible beauty.

Input

The first contains a single positive integer t (1t104) — the number of test cases.

For each test case, the first line contains a single integer n (1n105) — the number of colors.

The second line contains n integers ca1,ca2,,can (1cain) — the color of each position of the first tape. It is guaranteed that ca is a permutation.

The third line contains n integers cb1,cb2,,cbn (1cbin) — the color of each position of the second tape. It is guaranteed that cb is a permutation.

It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output

For each test case, print a single integer — the highest possible beauty.

Join Now for Solution:- 

No comments:

Post a Comment