37 lines
894 B
Python
37 lines
894 B
Python
import sys
|
|
|
|
input = sys.stdin.readline
|
|
|
|
|
|
if __name__ == "__main__":
|
|
n, q = map(int, input().split())
|
|
prices = list(map(int, input().split()))
|
|
|
|
if n <= 3:
|
|
s = sum(prices)
|
|
r1 = (100 - q) * s // 100
|
|
r2 = s - min(prices)
|
|
print(int(min(r1, r2)))
|
|
elif q == 0:
|
|
prices.sort()
|
|
s = 0
|
|
while len(prices) >= 3:
|
|
s += prices.pop()
|
|
s += prices.pop()
|
|
prices.pop()
|
|
s += sum(prices)
|
|
print(s)
|
|
elif q >= 34:
|
|
print(sum(prices) * (100 - q) // 100)
|
|
else:
|
|
prices.sort(reverse=True)
|
|
dp = [0] * (n + 1)
|
|
|
|
for i in range(1, n + 1):
|
|
dp[i] = dp[i - 1] + prices[i - 1] * (100 - q) // 100
|
|
g = 0
|
|
if i >= 3:
|
|
g = prices[i - 3] + prices[i - 2]
|
|
dp[i] = min(dp[i], dp[i - 3] + g)
|
|
print(dp[n])
|