Write an efficient script to process or transform a given dataset, focusing on performance and scalability.
Implement process_dataset(records). The input is an array of maps, each containing a string key and integer value. Return an array containing one summary map per distinct key, with fields key, count, and total. Sort summaries by descending total, then ascending key for ties. The solution should avoid comparing every pair of records and should scale linearly with the number of input records before the final sort.
def process_dataset(records):