题目来源:PAT乙级真题 1032 挖掘机技术哪家强 (20 分)
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Map<Integer,Integer> map = new HashMap<>(); int max = -1; int max_num = -1; for(int i = 0 ; i < n ; i++) { int num = sc.nextInt(); int score = sc.nextInt(); if(map.containsKey(num)) { map.put(num, map.get(num) + score); } else { map.put(num, score); } if(max < map.get(num)) { max = map.get(num); max_num = num; } } System.out.println(max_num + " " + max); } }
有一组数据会运行超时,目前没办法,留待补充……