1032. Which excavator technology is strong

topic here


Record the position of the maximum value and use the array subscript as the class number.


#include <iostream>
using namespace std;


intmain()
{
	int n;
	cin >> n;
	int a[100001] = {0};
	int max = 0;
	for(int i = 0; i < n; i++) {
		int num, grade;
		cin >> num >> grade;
		a[num] += grid;
		if(a[max] < a[num]) {
			max = num;
		}
	}
	
	cout << max << " " << a[max];
	
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325719099&siteId=291194637