A1259 | [COCI-2012_2013-contest3]#1 AERODROM
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
The Croatian delegation, consisting of M people, is travelling to IOI 2013 in Australia1 . They are currently waiting in a queue for check-in at the airport. There are N check-in desks open. Some officials work more efficiently than others, so the desks operate at different speeds. At the k-th desk, Tk seconds are required to finish check-in of a single passenger, and members of our delegation happen to know the exact numbers.
In the beginning, all desks are ready to accept the next passenger, and the delegation members are the only people in the queue. A person can only occupy (start check-in at) an available desk when all people in front of that person in the queue have left the queue (started, not necessarily finished, check-in)
already. At that moment, the person can immediately occupy an available desk (if there is one), but can also choose to wait for another (faster) desk to become available. Our delegation members, being computer science geeks, make this decision in such a way that the moment when all of them have finished check-in is as soon as possible. Your task is finding that moment in time.
Let us describe the scenario from the first example below. There are two desks, with processing times of 7 and 10 seconds, respectively. Out of the six people in the delegation, the first two immediately occupy the two desks. At time 7, the first desk is freed, and the third person occupies it. At time 10, the fourth person occupies the second desk. At time 14, the fifth person occupies the first desk. At time 20, the second desk is freed again, but the sixth person decides to wait another second (time 21) for the first desk to become available, and then occupy it. This way, the check-in is completed by time 2
8. If the sixth person hadn't waited for the faster desk, the check-in would have taken a total of 30 seconds.
In the beginning, all desks are ready to accept the next passenger, and the delegation members are the only people in the queue. A person can only occupy (start check-in at) an available desk when all people in front of that person in the queue have left the queue (started, not necessarily finished, check-in)
already. At that moment, the person can immediately occupy an available desk (if there is one), but can also choose to wait for another (faster) desk to become available. Our delegation members, being computer science geeks, make this decision in such a way that the moment when all of them have finished check-in is as soon as possible. Your task is finding that moment in time.
Let us describe the scenario from the first example below. There are two desks, with processing times of 7 and 10 seconds, respectively. Out of the six people in the delegation, the first two immediately occupy the two desks. At time 7, the first desk is freed, and the third person occupies it. At time 10, the fourth person occupies the second desk. At time 14, the fifth person occupies the first desk. At time 20, the second desk is freed again, but the sixth person decides to wait another second (time 21) for the first desk to become available, and then occupy it. This way, the check-in is completed by time 2
8. If the sixth person hadn't waited for the faster desk, the check-in would have taken a total of 30 seconds.
输入格式
The first line of input contains two positive integers, N (1 ≤ N ≤ 100 000), the number of desks, and M (1 ≤ M ≤ 1 000 000 000), the number of people in the delegation.
Each of the following N lines contains a number Tk from the problem statement (1 ≤ Tk ≤ 10^9).
Each of the following N lines contains a number Tk from the problem statement (1 ≤ Tk ≤ 10^9).
输出格式
The first and only line of output must contain the required minimum time in seconds.
输入输出样例
输入 #1
2 6 7 10
输出 #1
28
输入 #2
7 10 3 8 3 6 9 2 4
输出 #2
8
In test data worth a total of 75 points, the number M will be at most 300 000.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted