"""
活动选择问题 — 贪心算法
选择最多的不重叠活动
"""

def activity_selection(start, finish):
    """贪心选择最早结束的活动"""
    n = len(start)
    # 按结束时间排序
    activities = sorted(zip(start, finish), key=lambda x: x[1])

    selected = [activities[0]]
    last_finish = activities[0][1]

    for i in range(1, n):
        if activities[i][0] >= last_finish:
            selected.append(activities[i])
            last_finish = activities[i][1]

    return selected

if __name__ == "__main__":
    start = [1, 3, 0, 5, 8, 5]
    finish = [2, 4, 6, 7, 9, 9]

    result = activity_selection(start, finish)
    print("选择的活动 (开始, 结束):")
    for s, f in result:
        print(f"  [{s}, {f})")
    print(f"共 {len(result)} 个活动")
