#GL0000383. Hoán đổi đoạn để tối ưu GCD (Alter the GCD)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hoán đổi đoạn để tối ưu GCD (Alter the GCD)
Alter the GCD
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given two positive integer arrays and , you must perform exactly one operation: choose and swap with for every index in .
Afterward compute
Find the maximum possible and the number of distinct index pairs achieving it. Different segments count separately even if they produce identical arrays.
PHOJ input convention: Each .in file contains one test case, without a leading test count .
Input
The first line contains . The second line contains the values of , and the third line those of .
Output
Print the maximum score and the number of maximizing segments, separated by a space.
Subtasks
-
Subtask 1 (20 points): , .
-
Subtask 2 (30 points): , .
-
Subtask 3 (50 points): , .
Examples
Example 1
Input
2
18 13
15 20
Output
6 1
Explanation
Swapping the entire range produces arrays and , whose GCDs are and , totaling . The other two possible segments give smaller scores, so exactly one segment is optimal.
Example 2
Input
2
13 14
5 8
Output
2 3
Explanation
There are three segments: , , and . After any of these swaps, both array GCDs equal , so all three segments achieve score .