CSP 小明种苹果 201909-1

 输入:

3 3

73 -8 -6 -4

76 -5 -10 -8

80 -6 -15 0

输出:

167 2 23

输入:

2 2 

10 -3 -1

15 -4 0

输出:

17 1 4

注意: 1.一棵树的疏果个数可能全为零 2.当不同树的疏果个数相同时,输出满足条件的最小编号

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <vector>
 5 #include <cstring>
 6 #define mem(a,b) memset(a,b,sizeof(a))
 7 
 8 using namespace std;
 9 typedef long long LL;
10 const int mod = 1e9+7;
11 int dir[4][2] = {0,1,0,-1,1,0,-1,0};
12  int main()
13 {
14     LL n,m;
15     LL T = 0,maxn = 0,K = 0,P = -1;//T的初始值为-1,因为每棵树的疏果个数可能全为0,这时候保证输出序号最小
16     cin >> n >> m;
17     for(int i = 1; i <=n; i++) {
18         LL q;
19         maxn = 0;
20         cin >> q;
21         LL tt;
22         for(int j = 1; j <= m; j++) {
23              cin >> tt;
24              maxn += -tt;
25         }
26         T += q -maxn;
27         if(maxn > P) {//当疏果个数大于P时,进行更新
28             P = maxn;
29             K = i;
30         }
31     }
32     cout << T << " " << K << " " << P << endl;
33     return 0;
34 }
原文地址:https://www.cnblogs.com/LLLAIH/p/11633838.html