eolymp
bolt
Try our new interface for solving problems
Məsələlər

Fast Typing

Fast Typing

Vasya has little experience in typing, thus he has to look at the keyboard to locate the necessary keys, and still makes typos while doing so. For simplicity sake, we'll assume that the only type of typo he makes is replacing a character by another one. To correct those, he employs the following strategy: from time to time, he looks at the screen, and if there is any typo in the text, he removes all the characters from the end of the text to the first typo he made inclusive (i.e., he leaves only the correct part of the text intact) by pressing 'backspace' key several times, and continues typing from that position again. Pressing any key (including 'backspace') takes 1 unit of time, and looking at the screen takes \textit{t} units of time. Given the probabilities of making an error for each character in the text, compute the minimal possible expected time to type the entire text correctly (including verifying that by looking at the screen in the end and noticing no typos). The text is \textit{n} characters long, and the probability of mistyping \textit{i}-th character is equal to \textit{a}_i. \InputFile The input file contains two integer numbers \textit{\textbf{n}} and \textit{\textbf{t}} (\textbf{1} ≤ \textit{\textbf{n}} ≤ \textbf{3000}, \textbf{1} ≤ \textit{\textbf{t}} ≤ \textbf{10^6}), followed by \textit{\textbf{n}} real numbers \textit{\textbf{a}}\textbf{_i} (\textbf{10^\{-5\}} ≤ \textbf{a_i} ≤ \textbf{1/2}). \OutputFile Output one real number --- the minimal possible expected time. Your answer will be considered correct if it is within \textbf{10^\{-6\}} relative error of the exact answer.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
3 1
0.00001 0.5 0.00001
Çıxış verilənləri #1
8.000080000800008
Müəllif Пётр Митричев
Mənbə Зимняя школа, Харьков 2011, День 8