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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM