Skip to main content

Maximum profit HackerEarth Question

Maximum profit
Max. score: 100

In a game, you have the following:

  • Pile of N coins
  • List of restricted coins

Conditions

  • A player can choose at most coins one by one.
  • They cannot choose a value that is present in the list of restricted coins.
  • At the beginning of the game, the list of restricted coins is empty. Whenever a player selects a coin, it is added to their profit and also appended in the list of restricted coins.
  • A player can discard a coin even if it is not present in the list of restricted coins.

Task

Your task is to determine the maximum profit that a player can make.

Input format

  • The first line contains denoting the number of test cases.
  • In each test case:
    • The first line contains:
      • Two space-separated integers
      • Number of coins N
      • Maximum number of coins that a player can take K
    • The second line contains space-seperated integers denoting the value of the coins.

Output format

  • For each test case, print a single line denoting the maximum profit a player can make.

Constraints

  • 1T20000
  • 1N200000
  • 1 <= Value of Coin <= 1e9
  • Sum of N over all test cases will not exceed 200000
SAMPLE INPUT
 
1
5 4
2 3 3 2 2
SAMPLE OUTPUT
 
5
Explanation

Player can choose 2 and 3. He can not choose any number twice as it will be added to restricted coin list.

2 moves will be wasted as he has no other option so profit=2+3=5.

Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB
Marking Scheme:Score is assigned if any testcase passes.
Allowed Languages:Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, Racket, Ruby, Rust, Scala, Swift-4.1, Swift, TypeScript, Visual Basic

Comments

Popular posts from this blog

How to learn Database Management System

 What is DBMS ? DBMS stand for Database Management System and it is a software designed to Define, Manipulate, Retrive, Manage data in a Database. What are the application of DBMS ? It is needed where ever data is stored. Also it is a computerized record keeping system. Example of DBMS :- 1) E-Commerce website like Amazon, Flipkart, Shopcules, eBay, etc.             2) Online Television streaming or OTT Platform like ALT Balaji, Amazon                   Prime,Hotstar, Netflix, MX, etc.             3) It is used in Government Organisation like Bank, University, Police station,              Hospital, Railway, Airline, Human resource Department. 4) Social Media Platform like Whatsapp, Facebook, Instagram, Twitter, Linkedin,      etc.                    THATS ALL FOR TODAY !...

“Maintaining the Work from Home culture among employees for your startup”

  “Maintaining the Work from Home culture among employees for your startup”   While many of us are used to swanky offices in tony districts of our cities and whether we are ready or not, COVID-19 has transitioned many companies to enable remote work at scale. So, how can organizations seize the opportunity and think long-term? Thankfully, most organizations are equipping and have equipped themselves to continue business-as-usual by suddenly shifting gears and adopting work-from-home practices.   But working-from-home comes with its own set of unique challenges—both for the employees and employers. So how to make sure employees are engaged and motivated even when they are away from their traditional work environment? Some of the ways that can maximise the effectiveness of your new Work-From-Home setting: Community Building When employees suddenly start working away from their regular setting, they ar...

Redmi Note 10 Pro

Redmi Note 10 Pro (Dark Night, 6GB RAM, 128GB Storage) -120hz Super Amoled Display|64MP with 5mp Super Tele- Macro, Normal BUY NOW :  https://amzn.to/3wBTT8p