Approach
Sorting and greedy selection
For ABC326 C — Peak, 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
- 40 lines of Python from the credited upstream file abc326_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 3 4from bisect import bisect_left, bisect_right5from typing import List6 7 8def bisect_lt(sorted_array: List[int], value: int):9 """Find the largest element < x and its index, or None if it doesn't exist."""10 11 if sorted_array[0] < value:12 index: int = bisect_left(sorted_array, value) - 113 14 return index, sorted_array[index]15 16 return None, None17 18 19def main():20 import sys21 22 input = sys.stdin.readline23 24 n, m = map(int, input().split())25 a = sorted(list(map(int, input().split())))26 ans = 127 28 for i, ai in enumerate(a):29 j, value = bisect_lt(a, ai + m) 30 31 if j is not None:32 count = j - i + 133 ans = max(ans, count)34 35 print(ans)36 37 38if __name__ == "__main__":39 main()40