|
| 1 | +""" |
| 2 | +@Problem_Link: https://www.nowcoder.com/pat/6/problem/4041 |
| 3 | +""" |
| 4 | +import sys |
| 5 | + |
| 6 | + |
| 7 | +def check_higher(a, b): # If a > b |
| 8 | + if a[1] + a[2] > b[1] + b[2]: |
| 9 | + return True |
| 10 | + elif a[1] + a[2] < b[1] + b[2]: |
| 11 | + return False |
| 12 | + else: |
| 13 | + if a[1] > b[1]: |
| 14 | + return True |
| 15 | + elif a[1] < b[1]: |
| 16 | + return False |
| 17 | + else: |
| 18 | + if a[0] < b[0]: |
| 19 | + return True |
| 20 | + else: |
| 21 | + return False |
| 22 | + |
| 23 | + |
| 24 | +def qsort(s): |
| 25 | + if len(s) >= 2: |
| 26 | + mid = s[len(s) // 2] |
| 27 | + l, r = [], [] |
| 28 | + s.remove(mid) |
| 29 | + for i in s: |
| 30 | + if check_higher(i, mid): |
| 31 | + l.append(i) |
| 32 | + else: |
| 33 | + r.append(i) |
| 34 | + return qsort(l) + [mid] + qsort(r) |
| 35 | + else: |
| 36 | + return s |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + # Read N, L , H |
| 41 | + (N, L, H) = sys.stdin.readline().strip("\n").split(" ") |
| 42 | + # Convert to integer |
| 43 | + N, L, H = int(N), int(L), int(H) |
| 44 | + stuClass = [[], [], [], []] # Four clesses of students |
| 45 | + # Read students |
| 46 | + for i in range(N): |
| 47 | + (stuNum, dScore, cScore) = sys.stdin.readline().strip("\n").split(" ") |
| 48 | + dScore, cScore = int(dScore), int(cScore) |
| 49 | + # students failed the exam |
| 50 | + if dScore < L or cScore < L: |
| 51 | + continue |
| 52 | + # Class A Student |
| 53 | + if dScore >= H and cScore >= H: |
| 54 | + stuClass[0].append((stuNum, dScore, cScore)) |
| 55 | + # Class B Student |
| 56 | + elif dScore >= H and L <= cScore < H: |
| 57 | + stuClass[1].append((stuNum, dScore, cScore)) |
| 58 | + # Class C Student |
| 59 | + elif L <= cScore <= dScore < H: |
| 60 | + stuClass[2].append((stuNum, dScore, cScore)) |
| 61 | + # Class D Student |
| 62 | + else: |
| 63 | + stuClass[3].append((stuNum, dScore, cScore)) |
| 64 | + |
| 65 | + # Sort |
| 66 | + stuRank = [] |
| 67 | + for stu in stuClass: |
| 68 | + stuRank += qsort(stu) |
| 69 | + |
| 70 | + print(len(stuRank)) |
| 71 | + for stu in stuRank: |
| 72 | + print(stu[0], stu[1], stu[2]) |
0 commit comments