Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

Collections Module I

Problem Description

We had discussed about collections mode in python. Let's try the following problem using it.

There are N shops in the street and each shop has only single type of chocolate.

There are M number of children who are willing to pay Xi amount of money only if they get the chocolate of their desired type.

Find the total amount earned by all shopkeepers

Problem Constraints

1 <= N, M <= 105

1 <= Xi <= 109

1 <= Type of chocolate <= 109

Input Format

First line consist of an integer N.

Second line consist of N space separated integers denoting the type of chocolate at N shops.

Third line consist of an integer M.

Each of the next M lines consist of two integers Xi and type of desired chocolate.

Output Format

Print the total amount earned by all shopkeepers.

Example Input

Input 1:

10
1 2 1 3 2 5 6 10 11 15
5
50 1
20 3
25 3
5 12
20 11

Input 2:

5
11 11 2 3 2
4
50 2 
10 2
20 2
100 2

Example Output

Output 1:

 90

Output 2:

 60

Example Explanation

Explanation 1:

1st, 2nd and 5th children will get the chocolate, so the total money earned is 90.

Explanation 2:

1st and 2nd children will get the chocolate, so the total money earned is 60.



Start solving Collections Module I on Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test