Under construction

Still being built. Things may change

Tiling Terrace

Time limit2sMemory limit512 MB

Summary
Tile a row of soil and rock cells with 1, 2, and 3 cell tiles, using at most K single tiles, to maximize the total ghost score.
Level

Medium7 of 10

Topics
Dynamic programming, Binary search, String
Solved
No attempts yet

Problem

Talia has just bought an abandoned house on the outskirts of Jakarta. The house has a long yard that can be represented as a one-dimensional grid of 1×N1 \times N cells. To beautify the house, Talia will build a terrace on the yard by tiling its cells. Each cell contains either soil (.) or rock (#), and there are at most 50 rock cells.

Talia is afraid of ghosts, so she wants to use mystical tiles that repel them. There are three types of tiles:

  • Type-1: covers 1×11 \times 1 cell and can only be placed on a soil cell (.).
  • Type-2: covers 1×21 \times 2 cells and can only be placed on two consecutive soil cells (..).
  • Type-3: covers 1×31 \times 3 cells and can only be placed on consecutive soil-rock-soil cells (.#.).

A Type-1, Type-2, and Type-3 tile repels G1G_1, G2G_2, and G3G_3 ghosts per day, respectively. The following rules apply:

  • Tiles may not overlap. Each cell is covered by at most one tile.
  • At most KK Type-1 tiles may be used. Type-2 and Type-3 tiles have no limit.

Talia wants the terrace to repel as many ghosts as possible. She does not have to cover every cell as long as the number of ghosts repelled is maximal. Find that maximum number of ghosts repelled per day.

Input

The first line contains five integers NN, KK, G1G_1, G2G_2, G3G_3 (1≤N≤1000001 \le N \le 100000, 0≤K≤N0 \le K \le N, 0≤G1,G2,G3≤10000 \le G_1, G_2, G_3 \le 1000): the number of cells, the maximum number of Type-1 tiles, and the number of ghosts repelled per day by a Type-1, Type-2, and Type-3 tile, respectively. The next line contains a string of NN characters, each either . (soil) or # (rock). There are at most 50 rock cells.

Output

Output one integer: the maximum number of ghosts that can be repelled per day.

Examples3

  1. Example 1

    Input
    6 4 10 25 40
    ..#...
    
    Expected output
    75
    
  2. Example 2

    Input
    6 4 10 100 40
    ..#...
    
    Expected output
    210
    
  3. Example 3

    Input
    7 2 30 10 100
    ..#...#
    
    Expected output
    160