第一次看题目,可能会有一点蒙,但看了样例解释,一下就明白了。len用来统计蔬果之后的苹果总数,map容器用来统计第几棵树的蔬果总数,注意第几棵树的下标是从1开始的,所以应为mp[i + 1],第一次这样提交只得了70分,提示运行错误,后来发现|aij|<=10^6啥的,最后的计数可能会超过整型范围,所以为了方便,直接改成了long long,然后完美AC
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2){
if(p1.second>p2.second)
return p1.second>p2.second;
else
return p1.first<p2.first;
}
int main(){
int n,m;
cin >> n >> m;
map<ll,ll> mp;
ll len = 0;
for(int i = 0;i<n;i++){
int a,b;
ll sum = 0;
cin >> a;
len += a;
for(int j = 0;j<m;j++){
cin >> b;
sum += b;
}
len += sum;
mp[i+1] = abs(sum);
}
vector<pair<ll,ll> > v;
for(auto it = mp.begin();it!=mp.end();it++){
v.push_back(make_pair(it->first,it->second));
}
sort(v.begin(),v.end(),cmp);
cout << len << " " << v.begin()->first << " " << v.begin()->second;
return 0;
}