首页 > 试题广场 >

讨厌鬼进货

[编程题]讨厌鬼进货
  • 热度指数:4032 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}讨厌鬼需要采购 n 种货物,每种货物可通过以下方式获取:
\hspace{23pt}\bullet\, 在供应商 Aa_i 元购得第 i 种;
\hspace{23pt}\bullet\, 在供应商 Bb_i 元购得第 i 种;
\hspace{23pt}\bullet\, 在网购平台一次性购买全部 n 种,花费 x 元(不能拆分)。

\hspace{15pt}可以自由组合以上方式,只要最终每种货物都至少购买一件。求最小总花费。

输入描述:
\hspace{15pt}第一行输入两个整数 n,x\left(1\leqq n\leqq 10^5;\ 1\leqq x\leqq 10^9\right)
\hspace{15pt}第二行输入 n 个整数 a_1,a_2,\dots,a_n\left(1\leqq a_i\leqq 10^4\right)
\hspace{15pt}第三行输入 n 个整数 b_1,b_2,\dots,b_n\left(1\leqq b_i\leqq 10^4\right)


输出描述:
\hspace{15pt}输出一个整数,表示完成采购的最少花费。
示例1

输入

5 5
2 1 2 1 2
1 2 1 2 3

输出

5

说明

\hspace{15pt}直接选择网购 5 元即可完成。
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(n):
    if a[i] > b[i]:
        a[i] = b[i]
if x < sum(a):
    print(x)
else:
    print(sum(a))

发表于 2025-10-04 10:50:38 回复(0)
n,x = map(int,input().split())
cost = 0
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(n):
    cost += min(a[i],b[i])
print(min(x,cost))
发表于 2025-08-29 19:48:52 回复(0)
n,x = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

sum_ab = sum([min(a[i],b[i]) for i in range(n)])

print(min(sum_ab,x))
发表于 2025-07-08 17:33:31 回复(0)