AcWing--公路--贪心

5308. 公路 - AcWing题库(python)

# 输入、
# 站点数量  每升油的距离
n, d = map(int, input().split())

v = list(map(int, input().split()))
v = [0] + v

a = list(map(int, input().split()))

# 价格 油量 距离
res, oil, dist = 0, 0, 0
# 当前价格
p = a[0]
for i in range(2, n + 1):
    # 距离
    dist += v[i - 1]
    # 差多少油
    # 向上取整
    t = int((dist + d - 1) / d) - oil
    # 价格
    res += t * p
    oil += t
    p = min(p, a[i - 1])
print(res)

你可能感兴趣的:(算法,python)