#P5741. 【深基7.例10】旗鼓相当的对手 - 加强版

【深基7.例10】旗鼓相当的对手 - 加强版

Problem Description

There are N(N1000)N(N\le 1000) students taking the final exam, and we are given each student's information: name (a string of no more than 88 characters, with no spaces), and scores in Chinese, Math, and English (all natural numbers not exceeding 150150). If for a pair of students <i,j>\text{<}i,j\text{>}, the score difference in each subject is no more than 55, and the total score difference is no more than 1010, then this pair of students are "evenly matched opponents". Now we want to know, among these students, which pairs are "evenly matched opponents". Please output their names.

All names are given in lexicographical order, and when outputting, all opponent pairs should also be printed in lexicographical order. That is, for each pair, the lexicographical order of the first name should be smaller than the second. If the first names of two pairs are different, output the pair with the smaller first name first. If two pairs have the same first name but different second names, output the pair with the smaller second name first.

Input Format

The first line contains a positive integer NN, representing the number of students.

Starting from the second line, the next NN lines follow. In each line, first input a string representing the student's name, then input three natural numbers representing the scores in Chinese, Math, and English. They are separated by spaces.

Output Format

Output several lines. Each line contains two strings separated by a space, representing a pair of evenly matched opponents. Note the output ordering described in the problem statement.

3
fafa 90 90 90
lxl 95 85 90
senpai 100 80 91
fafa lxl
lxl senpai

Hint

Constraints: 1N10001 \leq N \leq 1000. Names are strings of length at most 88. Scores in Chinese, Math, and English are all natural numbers not exceeding 150150.

Translated by ChatGPT 5