Approach
Sorting and greedy selection
For ABC260 B — Better Students Are Needed!, the implementation first exposes a useful order, then scans that order while making locally justified choices.
- Choose the key that reveals the greedy or grouping structure.
- Sort the relevant records by that key.
- Scan in order, maintaining the invariant that makes each local choice safe.
Code notes
- 47 lines of Python from the credited upstream file abc260_b.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Sorting is typically the dominant term unless the subsequent scan uses a more expensive nested operation.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def main():5 import sys6 7 input = sys.stdin.readline8 9 n, x, y, z = map(int, input().split())10 a = list(map(int, input().split()))11 b = list(map(int, input().split()))12 13 math = sorted([(ai, i) for i, ai in enumerate(a)], key=lambda x: (x[0], -x[1]), reverse=True)14 english = sorted([(bi, i) for i, bi in enumerate(b)], key=lambda x: (x[0], -x[1]), reverse=True)15 both = sorted([(ai + bi, i) for i, (ai, bi) in enumerate(zip(a, b))], key=lambda x: (x[0], -x[1]), reverse=True)16 ok = [False] * n17 ans = list()18 19 def judge(test, limit):20 if limit == 0:21 return22 23 i, count = 0, 024 25 while i < n:26 _, t = test[i]27 28 if not ok[t]:29 ans.append(t + 1)30 ok[t] = True31 count += 132 33 if count == limit:34 return35 36 i += 137 38 judge(math, x)39 judge(english, y)40 judge(both, z)41 42 print(*sorted(ans), sep="\n")43 44 45if __name__ == "__main__":46 main()47