cswork / OA打开练习工作台

Abaka.aiOA #1

Task Scheduling (Parallel Same-Type with Memory Limit)

估计中等可在线判题

考点(AI 标注)贪心调度双指针滑窗哈希计数

Each task takes 1 unit of time. Two tasks can be processed in parallel if and only if they have the same type and their total memory is ≤maxMemory; every other task is processed alone. Find the minimum total processing time.

输入格式

The input contains N, maxMemory, N values of taskMemory, and N values of taskType. 1≤N≤200000, 1≤taskMemory[i]≤maxMemory≤10^9, 1≤taskType[i]≤10^9. This site specifies that every task can run alone, even if its memory does not allow it to run in parallel with another task.

输出格式

Output the minimum number of time units.

样例 1

输入:

4 10
7 2 3 9
1 2 1 3

输出:

3

样例 2

输入:

3 10
5 5 5
1 1 1

输出:

2

样例 3

输入:

2 10
2 9
3 3

输出:

2