小明种苹果

在这里插入图片描述

package ncu.edu.ccf;

import java.util.Scanner;

public class XiaoMingZhongPingGuo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] matrix = new int[n][m+1];
		
		//输入这个矩阵
		for(int i = 0; i < n; i++){
			for (int j = 0; j < m+1; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}
		
		//定义一维数组用来记录每行除第一元素以外的和
		int[] suGuo = new int[n];
		int max = suGuo[0];
		int count = 0;
		for(int i = 0; i < n; i++){
			for (int j = 1; j < m+1; j++) {
				//System.out.println(matrix[i][j]);
				suGuo[i] += matrix[i][j]; 
			}
			suGuo[i] = -suGuo[i];
			if(suGuo[i] > max){
				max = suGuo[i];
				count = i;
			}
		}
		count++;

		//求和
		int sum = 0;
		for(int i = 0 ; i < n; i++){
			sum += matrix[i][0] - suGuo[i];
		}
		System.out.println(sum+" "+count+" "+max);
	
	}

}


 

你可能感兴趣的:(#,csp,csp)