Problem: You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.  You want to introduce the restaurants in the following order:    * The restaurants are arranged in lexicographical order of the names of their cities.   * If there are multiple restaurants in the same city, they are arranged in descending order of score.  Print the identification numbers of the restaurants in the order they are introduced in the book.

Submission attempts (in order):
#b.py
n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        print(int(x[1]))
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
sublis.sort(key=lambda x:int(x[1]),reverse=True)
ans_lis.append(sublis)
sublis = []
sublis.append(x)       
print(ans_lis)
ans_lis = [item for sublist in ans_lis for item in sublist]
for x in ans_lis:
    print(x[2]+1)



#b.py
n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        print(int(x[1]))
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
sublis.sort(key=lambda x:int(x[1]),reverse=True)
ans_lis.append(sublis)
sublis = []
sublis.append(x)       
ans_lis = [item for sublist in ans_lis for item in sublist]
for x in ans_lis:
    print(x[2]+1)



#b.py
n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        print(int(x[1]))
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
sublis.sort(key=lambda x:int(x[1]),reverse=True)
ans_lis.append(sublis)
ans_lis = [item for sublist in ans_lis for item in sublist]
for x in ans_lis:
    print(x[2]+1)



#b.py
n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        print(int(x[1]))
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
for x in ans_lis:
    print(x[2]+1)



#b.py
n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
sublis.sort(key=lambda x:int(x[1]),reverse=True)
ans_lis.append(sublis)
sublis = []
sublis.append(x)       
ans_lis = [item for sublist in ans_lis for item in sublist]
for x in ans_lis:
    print(x[2]+1)



Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted