【CCF】——Xiaoming kind of apples (operation error resolution)

Insert picture description here
Insert picture description here

The first time I look at the topic, it may be a bit confusing, but after reading the sample explanation, I understand it at a glance. len is used to count the total number of apples after the fruits and vegetables, and the map container is used to count the total number of fruits and vegetables of the first tree. Note that the subscript of the first tree starts from 1, so it should be mp[i + 1], the first time This submission only scored 70 points, prompting a running error, and later found that |aij|<=10^6 or something, the final count may exceed the integer range, so for convenience, it was directly changed to long long, and then perfect 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;
}

Guess you like

Origin blog.csdn.net/weixin_45845039/article/details/108558451