Min Max Equality Codechef Solution | APRIL CHALLENGE

Codechef
Share:

Min Max Equality Codechef Solution

Chef found an array AA of NN elements. He defines a subarray as bad if the maximum element of the subarray is equal to the minimum element of the subarray.

More formally, a subarray [L,R][L,R] (1≤L≤R≤N)(1≤L≤R≤N) is bad if max(AL,AL+1,…,AR)=min(AL,AL+1,…,AR)max(AL,AL+1,…,AR)=min(AL,AL+1,…,AR).

Chef is allowed to change at most KK elements of the array.
Find the minimum number of bad subarrays Chef can obtain after changing at most KK elements of the array.

Input Format

  • First line will contain TT, the number of test cases. Then the test cases follow.
  • Each test case contains two lines of input, the first line contains two space-separated integers NN and KK – the number of elements in the array and the maximum number of elements Chef can change respectively.
  • The second line contains NN space-separated integers A1,A2,…,ANA1,A2,…,AN – the initial array.

Output Format

For each test case, output the minimum number of bad subarrays Chef can obtain after changing at most KK elements of the array.

Constraints

  • 1≤T≤3⋅1041≤T≤3⋅104
  • 1≤N≤1051≤N≤105
  • 1≤K≤N1≤K≤N
  • 1≤Ai≤1091≤Ai≤109
  • Sum of NN over all test cases does not exceed 3⋅1053⋅105.

Sample Input 1 

3
3 1
1 2 3
4 2
3 3 3 1
5 1
1 1 1 1 1

Sample Output 1 

3
4
7

Explanation

Test case 11: The minimum number of bad subarrays Chef can obtain is 33. Chef does not need to perform any operations. The subarrays where the maximum element is equal to the minimum element are [1,1],[2,2],[1,1],[2,2], and [3,3][3,3] where [L,R][L,R] denotes the subarray starting at index LL and ending at index RR.

Test case 22: The minimum number of bad subarrays Chef can obtain is 44. Chef can perform 22 operations and change the array to [2,4,3,1][2,4,3,1]. The subarrays where the maximum element is equal to the minimum element are [1,1],[2,2],[3,3],[1,1],[2,2],[3,3], and [4,4][4,4].

Min Max Equality Codechef  SOLUTION

Download Code
login to google play console, youtube video search by image, how to add a google account, which are the google apps, what is the google app, how to add a new google account, all the google apps, which service is the part of google, adsetting google, google data studio, google DNS, GCP console, bigquery, google studio, google api console, google app engine, anthos, google apis, google public DNS, google audio, google launcher, gcloud console, google compute engine, google webmaster console, google logged-in devices, gdrive unlimited,google console tools,google studio login,my google voice,hey google service,find similar images google, my google forms, www google com bd search, search using images in google,google image search scan,google sea console,website console google, google sound, gdrive storage for students, google site console, google console login, webmaster console, searc h console, google server down, google backup login, photo finder google, google products and services, google console tool, google image check, google cloud search is used for, google dashboard studio, google voice and audio activity,gcp dashboards, google services down, google go app, google dns down, google image identifier,check picture on google,google new launcher,google image finder online,image check google google google go, image finder on google, finding images on google, photo find google, find a picture in google, find the photo on google, picture find google, image find on google, find with photo google, image finder google online, google find with image, photo finder in google, google find image search, search using image in google, search on google with image, google server down today, google server down news

Read More Post Here

Leave a Comment

Your email address will not be published. Required fields are marked *

x