OCC '19 B2 - Cinematic

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Java 8 1.4s
Memory limit: 64M

Author:
Problem type

There are N movies that can be playing at a movie theater over the year. Each movie has an enjoyment rating of X_i. Each weekend, Momo can choose to watch a movie at the movie theater. There is only 1 movie playing every weekend. After Momo watches a movie, she cannot watch the same movie again even if it plays again. In the planet where Momo lives on, there are Y weeks in a year. Find the maximum sum of the enjoyment that Momo can obtain from watching the movies.

Input Specification

The first line of input contains N, the number of movies that can be played, and Y, the number of weeks in a year.

The next N lines of input contain the names of the movies.

The next line of input contains N integers, the enjoyment factor of each movie.

The next Y lines of input contain the name of the movie that is playing that week.

Output Specification

Output the maximum sum of enjoyment Momo can get from watching the movies.

Constraints

1 \le N, Y, X_i \le 10^5

The length of the title of each movie is less than 30 characters long and consists only of alphanumeric characters with no spaces.

Sample Input 1

3 5
Doestheblackmoonhowl
Oceaneyes
MobileOrchestra
10 9 8
Doestheblackmoonhowl
MobileOrchestra
Doestheblackmoonhowl
Doestheblackmoonhowl
Doestheblackmoonhowl

Sample Output 1

18

Explanation 1

Doestheblackmoonhowl and MobileOrchestra are shown during the 5 weeks of the year while Oceaneyes is not. The enjoyment factor of the two movies that are shown during the year is 18.


Comments

There are no comments at the moment.