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):
n=int(input())
sp=[]
for i in range(n):
    temp=list(map(str,input().split())) + [i+1]
    sp.append(temp)
    sp[i][1]=int(sp[i][1])
sp=sorted(sp,key=lambda x:(x[0],x[1]))

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        que=sorted(que,key=lambda x:(x[0],x[1]))[::-1]
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    else:
        que.append(sp[i])
        prev_rest = sp[i][0]

n=int(input())
sp=[]
for i in range(n):
    temp=list(map(str,input().split())) + [i+1]
    temp[1]=int(temp[1])
    sp.append(temp)
sp=sorted(sp,key=lambda x:(x[0],x[1]))

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        que=sorted(que,key=lambda x:(x[0],x[1]))[::-1]
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    que.append(sp[i])
    prev_rest = sp[i][0]
que=sorted(que,key=lambda x:(x[0],x[1]))[::-1]
for j in range(len(que)):
    ans_list=que.pop()
    print(ans_list[2])

n=int(input())
sp=[]
for i in range(n):
    temp=list(map(str,input().split())) + [i+1]
    temp[1]=int(temp[1])
    sp.append(temp)
sp=sorted(sp,key=lambda x:(x[0],x[1]))

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        que=sorted(que,key=lambda x:(x[0],x[1]))[::-1]
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    que.append(sp[i])
    prev_rest = sp[i][0]

n=int(input())
sp=[]
for i in range(n):
    temp=list(map(str,input().split())) + [i+1]
    sp.append(temp)
    sp[i][1]=int(sp[i][1])
sp=sorted(sp,key=lambda x:(x[0],x[1]))

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    else:
        que.append(sp[i])
        prev_rest = sp[i][0]

n=int(input())
sp=[]
for i in range(n):
    temp=list(map(str,input().split())) + [i+1]
    temp[1]=int(temp[1])
    sp.append(temp)
sp=sorted(sp,key=lambda x:(x[0],x[1]))

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        que=sorted(que,key=lambda x:(x[0],x[1]))
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    que.append(sp[i])
    prev_rest = sp[i][0]
que=sorted(que,key=lambda x:(x[0],x[1]))
for j in range(len(que)):
    ans_list=que.pop()
    print(ans_list[2])

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted