HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Search > problem:


50866 - Buy the cheapest

Guest
• Review clarifications (1)

Section problems

• 50786 - Top Question
• 50788 - Eight Puzzle
• 50504 - School contest
• 51056 - Welcome Picnic
• 50787 - Expected Value
• 51055 - The competition
• 50859 - Low performance
• 50826 - Olive Containers
• 50866 - Buy the cheapest
• 51077 - Grades Histogram
• 50785 - Swimming Contest
• 50999 - Overlapping Trips
• 50507 - Sequential Numbers
• 51057 - Number of students
• 50501 - The Highest Average
• 50434 - Row Min Subtraction
• 50980 - The smallest rectangle

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