輸入:
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 }