Вы находитесь на странице: 1из 3

07/07/2019 Distinct problem - July Easy' 19 | HackerEarth

LIVE EVENTS
01 : 28 : 10
HRS MIN SEC

July Easy' 19
LIVE

Jul 07, 2019, 09:30 AM IST - Jul 07, 2019, 12:30 PM IST

INSTRUCTIONS PROBLEMS SUBMISSIONS LEADERBOARD ANALYTICS JUDGE

 Problems / Distinct problem

Distinct problem
Max. Marks: 100

You are provided an array of size . In a single step, you can perform the following operation on the
array:

Select an element  ( ) and increment it by one

You are also given an additional integer . You are required to determine the minimum number of
steps required to make this array have at most distinct values.

Input format

First line: A single integer denoting the number of test cases in a single test le
For each test case:
First line: Two space-separated integers and
Next line: space-separated integers where the of these denotes

Output format

Print the answer for each test case on a new line. Refresh the page before starting to work on a new
test.

Constraints

Sum of over all the test cases in a test le is no more than 

SAMPLE INPUT  

1
4 2 ?

https://www.hackerearth.com/challenges/competitive/july-easy-19/algorithm/distinct-problem-f795442c/ 1/3
07/07/2019 Distinct problem - July Easy' 19 | HackerEarth

4 2 1 2

SAMPLE OUTPUT  
9
1

LIVE EVENTS
Explanation

You can select the element present at index and increment it by . Then the array transforms to
. Now, the array has only distinct elements, and this is the minimum possible answer.

Time Limit: 4.0 sec(s) for each input le.

Memory Limit: 256 MB

Source Limit: 1024 KB

Marking Scheme: Marks are awarded if any testcase passes.

Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino),
JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP,

Python, Python 3, Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Enter your code or Upload your code as le. Save C (gcc 5.4.0)  
1 /*
2 // Sample code to perform I/O:
3 #include <stdio.h>
4
5 int main(){
6 int num;
7 scanf("%d", &num); // Reading input from STDIN
8 printf("Input number is %d.\n", num); // Writing output to STDOUT
9 }
10
11 // Warning: Printing unwanted or ill-formatted data to output will cause the test cases t
12 */
13
14 // Write your code here
15

1:1

 Press Ctrl/Command+Spacebar for autocomplete suggestions (accuracy dependent on connection stability).

 Provide custom input

?
COMPILE & TEST SUBMIT
https://www.hackerearth.com/challenges/competitive/july-easy-19/algorithm/distinct-problem-f795442c/ 2/3
07/07/2019 Distinct problem - July Easy' 19 | HackerEarth

 Tip: You can submit any number of times you want. Your best submission is considered for computing total score.

LIVE EVENTS
Your Rating:

 View all comments

About Us Innovation Management

Technical Recruitment University Program

Developers Wiki Blog

Press Careers

Reach Us

Site Language: English | Terms and Conditions | Privacy |© 2019 HackerEarth

https://www.hackerearth.com/challenges/competitive/july-easy-19/algorithm/distinct-problem-f795442c/ 3/3

Вам также может понравиться