0% found this document useful (0 votes)
123 views2 pages

Maximize Array Score with Subarray Removal

The problem involves maximizing the score of an array by removing a contiguous subarray at most once. The score is defined as the length of the array minus the number of distinct elements. The task is to determine the optimal indices for removal to achieve the highest score while minimizing the final length of the array.

Uploaded by

Yhlas Yklymow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views2 pages

Maximize Array Score with Subarray Removal

The problem involves maximizing the score of an array by removing a contiguous subarray at most once. The score is defined as the length of the array minus the number of distinct elements. The task is to determine the optimal indices for removal to achieve the highest score while minimizing the final length of the array.

Uploaded by

Yhlas Yklymow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

9/2/25, 10:28 AM Problem - 2064B - Codeforces

|
stdfloat | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN

PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST

Codeforces Round 1005 (Div. 2)


B. Variety is Discouraged Finished
time limit per test: 1.5 seconds Practice
memory limit per test: 256 megabytes

Define the score of an arbitrary array b to be the length of b minus the number of distinct elements in b. For
example:
→ Virtual participation 
The score of [1, 2, 2, 4] is 1 , as it has length 4 and only 3 distinct elements (1 , 2 , 4 ).
Virtual contest is a way to take part in past contest,
The score of [1, 1, 1] is 2 , as it has length 3 and only 1 distinct element (1 ). as close as possible to participation on time. It is
supported only ICPC mode for virtual contests. If
The empty array has a score of 0 . you've seen these problems, a virtual contest is not
for you - solve these problems in the archive. If you
You have an array a. You need to remove some non-empty contiguous subarray from a at most once. just want to solve some problem from a contest, a
virtual contest is not for you - solve this problem in
the archive. Never use someone else's code, read
More formally, you can do the following at most once: the tutorials or communicate with other person
during a virtual contest.

pick two integers l, r where 1 ≤ l ≤ r ≤ n , and Start virtual contest


delete the contiguous subarray [al , … , ar ] from a (that is, replace a with [a1 , … , al−1 , ar+1 , … , an ] ).

Output an operation such that the score of a is maximum; if there are multiple answers, output one that minimises
→ Clone Contest to Mashup 
the final length of a after the operation. If there are still multiple answers, you may output any of them.

Input → Submit?
4
The first line contains an integer t (1 ≤ t ≤ 10 ) — the number of testcases.
Language: GNU G++20 13.2 (64 bit, winlibs)
The first line of each testcase contains an integer n (1 ≤ n ≤ 2 ⋅ 10
5
) — the length of the array a.
Choose
Choose File No file chosen
The second line of each testcase contains n integers a1 , a2 , … , an (1 ≤ ai ≤ n ). file:

The sum of n across all testcases does not exceed 2 ⋅ 10 .


5 Submit

Output
For each testcase, if you wish to not make a move, output 0 . → Contest materials

Otherwise, output two integers l and r (1 ≤ l ≤ r ≤ n ), representing the left and right bound of the removed Announcement (en)
subarray.
Tutorial (en)
The removed subarray should be chosen such that the score is maximized, and over all such answers choose any
of them that minimises the final length of the array.
→ CF GetRating
Example
input Copy *1100

3 Show All Tags


1
1 Contest Standings
5
1 1 1 1 1
4
2 1 3 2

output Copy

1 1
0
2 3

Note
In the first testcase, we have two options:

do nothing: the score of [1] is 1 − 1 = 0.


remove the subarray with l = 1, r = 1 : we remove the only element, and we get an empty array with score 0 .

Therefore, the maximum score possible is 0 . However, since we need to additionally minimise the final length of the
array, we must output the second option with l = r = 1. Note that the first option of doing nothing is incorrect,
since it has a longer final length.
In the second testcase, no subarray is selected, so after which a is still [1, 1, 1, 1, 1]. This has length 5 and 1
distinct element, so it has a score of 5 − 1 = 4. This can be proven to be a shortest array which maximises the
score.

In the third testcase, the subarray selected is [2, 1, 3, 2], after which a becomes [2, 2]. This has length 2 and 1
distinct element, so it has a score of 2 − 1 = 1. This can be proven to be a shortest array which maximises the
score.

[Link] 1/2
9/2/25, 10:28 AM Problem - 2064B - Codeforces

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Sep/02/2025 [Link]UTC+5 (h1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions

Supported by

[Link] 2/2

You might also like