Server Farm

Time limit: 0.06s Memory limit: 32MB Input: Output:

William wants to exploit his new independent house for setting up a brand-new server farm, and start earning money immediately! Since his budget is pretty limited, he started this ambitious project by collecting obsolete PCs from the recycling bin for electronic waste. He gathered this way NN fully functional computers with diverse capabilities. In particular, the ii-th computer has computing power of FiF_i nanoFLOPS and is powered via a plug of type TiT_i, which can be either:

  • Ti=T_i = L10, if the plug conforms to the Type L/10amp standard;
  • Ti=T_i = L16, if the plug conforms to the Type L/16amp standard.

He also found a very long power strip consisting of MM sockets, where the ii-th of them can be of three different types SiS_i:

  • SiS_i = L10, if the socket is designed for Type L/10amp plugs;
  • SiS_i = L16, if the socket is designed for Type L/16amp plugs;
  • SiS_i = bipasso, if the socket is designed to accommodate both (otherwise incompatible) types.

Task

Help William find the assignment of plugs into compatible sockets which allows for the highest total amount of nanoFLOPS!

Input data

The first line contains two integers NN, MM. The second line contains NN integers FiF_i. The third line contains NN space-separated plug types TiT_i. The fourth line contains MM space-separated socket types SiS_i.

Output data

You need to write a single line with an integer: the maximum amount of nanoFLOPS that William can produce by connecting their PCs into compatible plugs.

Constraints and clarifications

  • 1N,M20 0001 \leq N,M \leq 20 \ 000
  • 1Fi20 0001 \leq F_i \leq 20 \ 000
# Points Constraints
1 5 Examples.
2 10 FiF_i is equal for all PCs.
3 25 There are no bipasso sockets.
4 30 H,W50H,W \leq 50
5 30 No additional constraints.

Example 1

stdin

7 5
120 310 570 250 740 460 880
L10 L16 L10 L10 L16 L16 L16
bipasso L10 L16 L10 bipasso

stdout

2900

Explanation

William can arrange in the power socket the PCs corresponding to the following amount of nanoFLOPS (in order): 460+570+880+250+740460 + 570 + 880 + 250 + 740.

Example 2

stdin

10 7
690 950 300 470 520 380 750 990 300 440
L10 L16 L10 L10 L16 L10 L10 L10 L16 L10
L16 L16 bipasso bipasso L16 L10 L16

stdout

4200

Explanation

A possible arrangement is the following: 520+(empty)+990+690+300+750+520520 + \text{(empty)} + 990 + 690 + 300 + 750 + 520.

Log in or sign up to be able to send submissions!