Loading...

BISHI43 讨厌鬼进货

在这里插入图片描述

求解代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        String[] s = br.readLine().split("\\s+");

        int n = Integer.parseInt(s[0]);
        long x = Long.parseLong(s[1]);

        String[] strA = br.readLine().split("\\s+");
        String[] strB = br.readLine().split("\\s+");

        long sum = 0;

        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(strA[i]);
            int b = Integer.parseInt(strB[i]);

            sum += Math.min(a, b); // 每种货物选A/B中更便宜的
        }
        long res = Math.min(x, sum);// 比较单独买总和与网购成本
        out.println(res);
        out.flush();
        out.close();
        br.close();

    }
最后更新于 2026-04-05 17:35:33
Code Road Record