欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1690C.Restoring the Duration of Tasks
Restoring the Duration of Tasks
Recently, Polycarp completed successive tasks.
For each completed task, the time is known when it was given, no two tasks were given at the same time. Also given is the time when the task was completed. For each task, there is an unknown value () — duration of task execution.
It is known that the tasks were completed in the order in which they came. Polycarp performed the tasks as follows:
- As soon as the very first task came, Polycarp immediately began to carry it out.
- If a new task arrived before Polycarp finished the previous one, he put the new task at the end of the queue.
- When Polycarp finished executing the next task and the queue was not empty, he immediately took a new task from the head of the queue (if the queue is empty — he just waited for the next task).
Find (duration) of each task.
Input
The first line contains a single integer () — the number of test cases.
The descriptions of the input data sets follow.
The first line of each test case contains one integer ().
The second line of each test case contains exactly integers ().
The third line of each test case contains exactly integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each of test cases print positive integers — the duration of each task.
Note
First test case:
The queue is empty at the beginning: . And that's where the first task comes in. At time , Polycarp finishes doing the first task, so the duration of the first task is . The queue is empty so Polycarp is just waiting.
At time , the second task arrives. And at time , the third task arrives, and now the queue looks like this: .
At the time , Polycarp finishes doing the second task, as a result, the duration of the second task is .
And at time , Polycarp immediately starts doing the third task and finishes at time . As a result, the duration of the third task is .
An example of the first test case.
Samples
4
3
0 3 7
2 10 11
2
10 15
11 16
9
12 16 90 195 1456 1569 3001 5237 19275
13 199 200 260 9100 10000 10914 91066 5735533
1
0
1000000000
2 7 1
1 1
1 183 1 60 7644 900 914 80152 5644467
1000000000
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |