Approach
Sorting and greedy selection
For ABC331 C — Sum of Numbers Greater Than Me, 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
- 41 lines of Python from the credited upstream file abc331_c.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 3from bisect import bisect_left, bisect_right4from typing import List5 6 7def bisect_le(sorted_array: List[int], value: int):8 """Find the largest element <= x and its index, or None if it doesn't exist."""9 10 if sorted_array[0] <= value:11 index: int = bisect_right(sorted_array, value) - 112 13 return index, sorted_array[index]14 15 return None, None16 17 18def main():19 import sys20 from itertools import accumulate21 22 input = sys.stdin.readline23 24 n = int(input())25 a = list(map(int, input().split()))26 inf = 10**1827 d = [0] + sorted(a) + [inf]28 c = list(accumulate(d))29 ans = list()30 31 for ai in a:32 i, value = bisect_le(d, ai) 33 34 ans.append(c[n] - c[i])35 36 print(*ans)37 38 39if __name__ == "__main__":40 main()41