**
求助,Java编程。
**
有n个客户需要分发礼物,现有甲、乙两个仓库,两个仓库的库存分别为a、b,(0<a,b<=n<=a+b),d[i]为甲仓库给第i个客户发礼物的快递费,p[i]为乙仓库给第i个客户发礼物的快递费,问总收费最小。
输入:
第一行为n个客户
第二行为甲乙仓库的库存
接着是甲乙仓库给n个客户发货的收费标准
3
1 2
13 19
4 9
10 20
输出:
38
最小
19+9+10=38
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
Scanner scab = new Scanner(System.in);
String str = scab.nextLine();
int a = Integer.parseInt(str.split(" ")[0]);
int b = Integer.parseInt(str.split(" ")[1]);
int[][] cost = new int[n][2];
for (int i = 0; i < cost.length; i++) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] s1 = s.split(" ");
for (int j = 0; j < cost[i].length; j++) {
cost[i][j] = Integer.parseInt(s1[j]);
}
}
// int n = 3, a = 2, b = 2;
// int[][] cost = {
// {13, 19},
// {9, 4},
// {20, 10}
// };
for (int j = 0; j < n; j++) {
for (int i = 1; i < n; i++) {
int[] temp = new int[2];
if ((cost[i][0] - cost[i][1]) < (cost[i - 1][0] - cost[i - 1][1])) {
temp[0] = cost[i - 1][0];
temp[1] = cost[i - 1][1];
cost[i - 1][0] = cost[i][0];
cost[i - 1][1] = cost[i][1];
cost[i][0] = temp[0];
cost[i][1] = temp[1];
}
}
}
for (int i = 0; i < cost.length; i++) {
for (int j = 0; j < cost[i].length; j++) {
System.out.print(cost[i][j] + " ");
}
System.out.println();
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (i < a) {
sum += cost[i][0];
System.out.println(sum);
} else {
sum += cost[i][1];
}
}
System.out.println(sum);
}
}