# Java最大收益

## 标题Problem A: 最大收益

Time Limit: 1 Sec Memory Limit: 128 MB

Description

Elly的叔叔经营一家电脑装配公司ShumenSoft，为了使公司得到最大获益，他们日以继夜地工作着。

Input

Output

Sample Input Copy

4 2
1 2 3 4
5 6

Sample Output Copy

2 39

Java代码：

代码在你们的作业系统上运行通不通过我不知道！！！







Java代码：

import java.util.*;
public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] cpu = new int[n];
int[] moniter = new int[m];
for (int i = 0; i < n; i++)
{
cpu[i] = sc.nextInt();
}
for (int i = 0; i < m; i++)
{
moniter[i] = sc.nextInt();
}
int temp;
for(int i=0;i<cpu.length-1;i++)
{
for(int j=0;j<cpu.length-i-1;j++)
{
if(cpu[j]<cpu[j+1])
{
temp = cpu[j];
cpu[j] = cpu[j+1];
cpu[j+1] = temp;
}
}
}for(int i=0;i<moniter.length-1;i++)
{
for(int j=0;j<moniter.length-i-1;j++)
{
if(moniter[j]<moniter[j+1])
{
temp = moniter[j];
moniter[j] = moniter[j+1];
moniter[j+1] = temp;
}
}
}
int count=n>m?m:n;
int account=0;
for(int i=0;i<count;i++)
{
account+=cpu[i]*moniter[i];
}
System.out.print(count+" ");
System.out.print(account+" ");
//for (int i = 0; i < n; i++)
//{
//System.out.print(cpu[i]+" ") ;
//}
//System.out.println(" ");
//for (int i = 0; i < m; i++)
//{
//System.out.print(moniter[i]+" ") ;
//}
//System.out.println(" ");
}
}


## 测试代码：！！！

import java.util.*;
public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int n = sc.nextInt();
int m = sc.nextInt();
int[] cpu = new int[n];
int[] moniter = new int[m];
for (int i = 0; i < n; i++)
{
cpu[i] = sc.nextInt();
}
for (int i = 0; i < m; i++)
{
moniter[i] = sc.nextInt();
}
int temp;
for(int i=0;i<cpu.length-1;i++)
{
for(int j=0;j<cpu.length-i-1;j++)
{
if(cpu[j]<cpu[j+1])
{
temp = cpu[j];
cpu[j] = cpu[j+1];
cpu[j+1] = temp;
}
}
}for(int i=0;i<moniter.length-1;i++)
{
for(int j=0;j<moniter.length-i-1;j++)
{
if(moniter[j]<moniter[j+1])
{
temp = moniter[j];
moniter[j] = moniter[j+1];
moniter[j+1] = temp;
}
}
}
int count=n>m?m:n;
int account=0;
for(int i=0;i<count;i++)
{
account+=cpu[i]*moniter[i];
}
System.out.print(count+" ");
System.out.print(account+" ");
//for (int i = 0; i < n; i++)
//{
//System.out.print(cpu[i]+" ") ;
//}
//System.out.println(" ");
//for (int i = 0; i < m; i++)
//{
//System.out.print(moniter[i]+" ") ;
//}
//System.out.println(" ");
}

}
}


## 测试结果显示是对的🤦‍🤦‍🤦‍

q其他对于这个以及其他的程序交流，欢迎欢迎~

## END END END

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

美迪的麦柯

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
10-19 4499

03-20 1915
01-25 6133
03-20 1084
09-08 320
10-13 2481
05-13 267
11-12 576