首页 > 试题广场 >

讨厌鬼进货

[编程题]讨厌鬼进货
  • 热度指数:225 时间限制: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 = 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)
#include <ios>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,x;
    cin>>n>>x;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=min(a[i],b[i]);
    }
    cout<<min(sum,x);
    return 0;
}
// 64 位输出请用 printf("%lld")
发表于 2025-07-05 16:23:32 回复(0)