欢迎访问我的CCF认证解题目录
题目描述
思路过程
直接记录、比较就可以了
代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] line = br.readLine().split(" ");
int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);
int sum = 0;//总数
int maxCnt = 1;//最大掉落数的下标
int maxSum = 0;//最大掉落数
for ( int i = 1; i <= n; i++ ) {
line = br.readLine().split(" ");
int temp = Integer.parseInt(line[0]);//当前树的苹果数
int downNum = 0;//掉落的数量
for ( int j = 1; j <= m; j++ ) {
downNum += Integer.parseInt(line[j]);
}
downNum = Math.abs(downNum);
if ( downNum > maxSum ) {
maxSum = downNum;
maxCnt = i;
}
sum += temp-downNum;
}
System.out.printf("%d %d %d", sum, maxCnt, maxSum);
}
}