GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 7 June 2022

[Solution] Restoring the Duration of Tasks Codeforces Solution

C. Restoring the Duration of Tasks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, Polycarp completed n successive tasks.

For each completed task, the time si is known when it was given, no two tasks were given at the same time. Also given is the time fi when the task was completed. For each task, there is an unknown value di (di>0) — duration of task execution.

It is known that the tasks were completed in the order in 

Solution Click Below:-  CLICK HERE

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 di (duration) of each task.

Input

The first line contains a single integer t (1t104) — the number of test cases.

The descriptions of the input data sets follow.

The first line of each test case contains one integer n (1n2105).

The second line of each test case contains exactly n integers s1<s2<<sn (0si109).

The third line of each test case contains exactly n integers f1<f2<<fn (si<fi109).

It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output

For each of t test cases print n positive integers d1,d2,,dn — the duration of each task.

No comments:

Post a Comment