Codeforces Round 1099 (Div. 2)

Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
2231 Codeforces Round 1099 (Div. 2) FINISHED False 7200 2129080 May 21, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 16258 ) B Another Sorting Problem PROGRAMMING constructive algorithms

You are given an array (a_1, a_2, \ldots, a_n). You can perform the following operation on this array at most once: Choose a positive integer (k), as well as a subsequence (b_1, b_2, \ldots, b_m) of the array (a)(^{\text{∗}}) and add (k) to each element of this subsequence, that is, for each (i) perform (a_{b_i} := a_{b_i} + k). You need to determine whether it is possible to sort the array in nondecreasing order by performing this operation at most once. (^{\text{∗}})A sequence (b) is a subsequence of a sequence (a) if (b) can be obtained from (a) by the deletion of several (possibly, zero or all) element from arbitrary positions. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. In the first line of each test case, one integer (n) is given ((1 \leq n \leq 2 \cdot 10^5)) — the length of the array (a). In the second line of each test case, (n) integers (a_1, a_2, \ldots, a_n) are given ((1 \leq a_i \leq 10^9)). It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, print " Yes " if it is possible to sort the array by performing the operation at most once. Otherwise, print " No ". You may print the answer in any case. For example, " YeS ", " YES ", " NO ", " nO " will also be accepted. In the first test case, the array is already sorted, so the operation does not need to be performed at all. In the second test case, it can be shown that it is impossible to sort the array using such an operation. In the third test case, choose (k = 6) and choose the subsequence (2, 4, 6) as (b). Then after this operation, the array (a) becomes (8, \textbf{9}, 9, \textbf{10}, 10, \textbf{11}, 11) (the elements of the chosen subsequence are shown in bold).

Tutorials

Submissions

No solutions yet.