HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN112 Questions 2016 > problem:


15-PE-2. 50866 - Buy the cheapest

CEN112 Questions 2016

Start: Mar.30.2016 at 03:10:22 PM
Finish: Apr.01.2016 at 05:00:00 AM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 15-HW-5. 50935 - Max Discount
• 15-MdtE-1. 50915 - Trip to Korca
• 15-MdtE-2. 50916 - Ascending Num...
• 15-MdtE-3. 50913 - Manhattan Distance
• 15-MdtE-4. 50917 - Descending Nu...
• 15-MdtE-5. 50912 - Trip to Librazhd
• 15-MdtE-6. 50914 - Buy 3, Pay 2
• 15-PE-1. 50865 - Apartment Building...
• 15-PE-2. 50866 - Buy the chea...
• 15-PE-4. 50868 - Sort Frequencies
• 15-PE-5. 50869 - Birthday Celebration
• 15-PE-7. 50871 - Harmonic Mean
• 15-PE-8. 50872 - Top M Grades
• 15-PE2-1. 50980 - The smallest rect...
• 15-PE2-2. 50981 - Top popular m-st...
• 15-PE2-2. 50984 - Top m hardworki...
• 15-PE2-2. 51086 - Top popular student

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Buy the cheapest

It is time for economy. The director of the company has collected the price of items from two markets. They want to compare the prices and choose the cheaper one.

Question: Write a program that reads price of n items from two markets. And then, find the cheapest total price for m items.

Input specification
You will be first given two numbers: the number of items (n) and the number of items to search (m) where 0 ≤ m ≤ 5000 and 0 ≤ n ≤ 25,000. Then in the following n lines, you will be given information from two markets. Every line contains:

  • Product ID: an integer between 0 and 60,000.
  • Price of item from two markets: two integers between 1 and 10,000.
Then, the last m lines contain the IDs of products to buy.

Output specification: Show one integer: total minimum price for m items.
Note: If the item is not in the list, you don't buy it.

Sample Input I
10 5
3 942 754
15 937 372
17 762 202
8 617 940
10 744 528
20 836 330
21 594 236
6 491 448
12 719 18
23 281 954
8
3
12
21
16
Sample Output I
1625

Explanation: Here are the min prices for m products

Product IDMin Price
 Product # 8617
 Product # 3754
 Product # 1218
 Product # 21236
 Product # 16  Not in the list
Then, the total price is 1,625.



Для отправки решений необходимо выполнить вход.

www.contester.ru