HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50866 - Buy the cheapest

Guest
• Review clarifications (1)

Volume problems

• 50786 - Top Question
• 50788 - Eight Puzzle
• 50499 - Table to Row
• 50823 - Secret Number
• 50853 - Parking Place
• 50496 - Falling Bricks
• 50802 - Comparing Exams
• 50517 - Confusion Matrix
• 50866 - Buy the cheapest
• 50785 - Swimming Contest
• 51011 - Decoding the Path
• 50515 - Lines - Revisited
• 50999 - Overlapping Trips
• 50507 - Sequential Numbers
• 50449 - The biggest result
• 50434 - Row Min Subtraction
• 50442 - Polynomial Addition

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