CSP历年真题201909-1-小明种苹果

CSP历年真题201909-1-小明种苹果_第1张图片
CSP历年真题201909-1-小明种苹果_第2张图片

代码

#include<cstdio>
#include<cmath>
const int maxnm = 10000;
int a[maxnm][maxnm] = {0};
int main(){
	int N, M, T = 0, k, P = 0;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M+1; j++){
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 1; i <= N; i++){
		for(int j = 2; j <= M+1; j++){
			a[i][M+2] += abs(a[i][j]);
			if(a[i][M+2] > P){
				P = a[i][M+2];
				k = i;
			}
		}
		T += (a[i][1] - a[i][M+2]);
	}
	printf("%d %d %d", T, k, P);
	return 0;
}

你可能感兴趣的:(CSP认证)