Cleaning the Desktop

5

2 votes
Easy
Problem

You feel your desktop is cluttered with unwanted icons. You want delete icons you don’t need. All icons are arranged in a straight line. You can either delete an individual icon, which takes p units of time per deletion or delete a contiguous sequence of unwanted icons which takes q units of time for each contiguous sequence deletion irrespective of the length. Find the minimum time required to unclutter your desktop.

INPUT
1st line contains N, the total number of icons.
2nd line contains two integers p and q respectively, the time required to delete a single icon and a contiguous sequence of icons.
3rd line contains N spaced integers, p1, p2, … , pn, denoting the desktop icons in order. If pi is 1 the ith icon is to be deleted; pi is 0 otherwise.

CONSTRAINTS
1 <= N <= 105
1 <= p, q <= 1000
0 <= pi <= 1

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?