Chef Segment CodeChef Solution
Table of Contents
We Are Discuss About CODECHEF SOLUTION
Chef Segment CodeChef Solution
Problem
You are given an array � consisting of � integers. You are allowed to rearrange the elements of the array in any order.
A segment [�,�] of the array is considered beautiful if, for every pair (�,�) where �≤�≤�≤�, either ��mod ��=0 or ��mod ��=0. Note that mod
denotes the modulo operation.
The score of a beautiful segment [�,�] is calculated as follows:
score
([�,�])=min(��,��+1,…,��)⋅(�−�+1)
Your task is to determine the maximum possible score of a beautiful segment within the given array �.
Input Format
- The first line of input will contain a single integer �, denoting the number of test cases.
- The first line of each test case contains an integer � – the length of the array �.
- The second line of each test case contains � space-separated integers �1,�2,…,��, denoting the array.
Output Format
For each test case, output on a new line, the maximum possible score of a beautiful segment.
Constraints
- 1≤�≤105
- 1≤�,��≤105
- The sum of � over all test cases won’t exceed 3⋅105.
- The sum of max(��) over all test cases won’t exceed 3⋅105.
Sample 1:
2 4 2 3 4 6 5 4 4 8 10 4
6 16
Explanation:
Test case 1: The array elements can be rearranged as [3,6,2,4].
The beautiful segments are [1,1],[2,2],[3,3],[4,4],[1,2],[2,3],[3,4].
score
([1,2])=min(�1,�2)⋅2=6, which is the maximum possible score.
Test case 2: The array elements can be rearranged as [4,4,8,4,10].
The beautiful segment [1,4] has the maximum score of 16.
6 digit code appear after 69 seconds.
Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer Then Follow US HERE and Join Telegram.
If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE