PTA (Basic Level) 1032. Excavator strong Which

To illustrate the facts Excavator Which in the end strong, PAT excavator organized a skills competition. Now you that the statistics of the strongest technical schools based on results of the competition.

Input formats:

Input line 1 given positive integer of not more than 105 N , i.e. the number of entries. Then N lines, each and every participant is given the information and results, including the school they represent numbers (starting with 1 numbered consecutively), and game scores (percentile), separated by a space.

Output formats:

Given the highest total score in a row, the number of schools, and their total score, separated by a space. The only answer is to ensure that the subject is not tied.

Sample input:
6
3 65
2 80
1 100
2 70
3 40
3 0
Sample output:
2 150
Thinking
  • With rows of barrels thought, the array index number is called, then the position can be used together with the corresponding results
Code
#include<bits/stdc++.h>
using namespace std;
int a[100010] = {0};
int main()
{
    int n;
    scanf("%d", &n);

    int id, score;
    int max_id = -1;
    while(n--)
    {
        scanf("%d%d", &id, &score);
        max_id = max(id, max_id);
        a[id] += score;
    }
    int ans_id;
    int ans_score = -1;
    for(int i=0;i<=max_id;i++)
    {
        if(a[i] > ans_score)
        {
            ans_score = a[i];
            ans_id = i;
        }
    }
    cout << ans_id << " " << ans_score;
    return 0;
}
Quote

https://pintia.cn/problem-sets/994805260223102976/problems/994805289432236032

Guess you like

Origin www.cnblogs.com/MartinLwx/p/11606422.html