水
记录一下序列即可
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2A
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
IDictionary<string, List<Tuple<int, int>>> score = new Dictionary<string, List<Tuple<int, int>>>();
for (int i = 0; i < n; i++)
{
string[] tmp = Console.ReadLine().Split();
int s = int.Parse(tmp[1]);
if (!score.Keys.Contains(tmp[0]))
{
score.Add(new KeyValuePair<string, List<Tuple<int, int>>>(tmp[0], new List<Tuple<int, int>>()));
}
else
{
s += score[tmp[0]].Last().Item1;
}
score[tmp[0]].Add(new Tuple<int, int>(s, i));
}
List<string> names = new List<string>();
int finalScore = 0;
foreach (var item in score)
{
if (names.Count == 0)
{
names.Add(item.Key);
finalScore = item.Value.Last().Item1;
}
else
{
if (item.Value.Last().Item1 > finalScore)
{
names.Clear();
names.Add(item.Key);
finalScore = item.Value.Last().Item1;
}
else if (item.Value.Last().Item1 == finalScore)
{
names.Add(item.Key);
}
}
}
string maxName = "";
if (names.Count > 1)
{
int earliestRound = 99999;
foreach (var name in names)
{
for (int i = 0; i < score[name].Count; i++)
{
if (score[name][i].Item1 >= finalScore && score[name][i].Item2 < earliestRound)
{
maxName = name;
earliestRound = score[name][i].Item2;
break;
}
}
}
}
else
{
maxName = names[0];
}
Console.WriteLine(maxName);
}
}
}