This problem can be solved by $DP$. For each type $i$, Camila has *three* choices $-$ buy $i-$th type, buy $n+1-i-$th type or skip both. So, if we group each $i$ and $n+1-i$ type, there will be total $n/2$ groups. Now, take *groups and buy count* as state of dp and in each dp state there will be *three* transitions as skip this group, greedily buy books from $i-$th type and greedily buy books from $n+1-i-$th type and then return the *minimum price* among them. Overall complexity will be $O(X * K)$.

80% Solution Ratio

adnan_tokyEarliest,

likhon5Fastest, 0.1s

Shuvo_MalakarLightest, 4.3 MB

antihashShortest, 1434B

Toph uses cookies. By continuing you agree to our Cookie Policy.