Posts

Showing posts from June, 2024

1726A - Mainak and Array Solution - CodeForces

 Problem Link: https://codeforces.com/contest/1726/problem/A Let's consider an array, for example the first one from the test case, [1, 3, 9, 11, 5, 7] As k is any positive number we can choose we can rotate the array any number of times we want. So we have no limit on how many times we rotate. However if we rotate we would have to rotate only in one range. We cannot change the value of l and r later. Now consider two cases, Case 1: If we would keep the first value (a_1) fixed, then what should be the value of the last element (a_n)? Of course, the one for which the absolute difference between a1 (1) and that value would be maximum right? In this case, the value should be 11 as |1-11| = 10. What range should we rotate so that we don't miss any value? It should be all the value from a_2 to a_n, isn't it? (In this case 3, 9... 7, if we keep rotating the values there will certainly a time come when 11 will be at the last).  Case 2: Now, if we keep the last value fixed, simil...