Cramming Assignments


Submit solution


Points: 1
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
C, C++, Java, Python

It is the last week of semester, and you have many assignments due. You are hard at work at them, but you have a very short attention span and ADHD too. Sometimes when working on one assignment, you remember another assignment you're meant to be doing and get distracted, switching to work on the new one. This happens multiple times. Can you find how long it will take to finally complete all of your assignments?

You will keep working on each current assignment until you either finish it, or remember a different assignment. If you finish it, you will resume working on the most recent interrupted assignment, or do nothing if there are no previous assignments. If you haven't finished it when you remember the next assignment, your progress will be interrupted and you'll have to come back to it later, when you've finished the subsequent assignments.

Input

The first line contains a single integer n\ (1 \leq n \leq 10^5), the number of assignments, which are labelled 1 through n.

The next line contains n space-separated integers a_i\ (1 \leq a_i \leq 10^3), the amount of time each assignment takes to complete.

The next line contains n-1 unique space-separated integers t_i\ (1 \leq t_i \leq 10^6). You start working on the first assignment at t=0, and then you remember each of the following assignments at each of t_i, interrupting what your were previously working on. Since there are n assignment lengths and n-1 interruption times, the first t_i is the start time of the second assignment (as the first assignment is started immediately).

Output

Output when you will complete each assignment, on separate lines, as "Completed assignment i at time t" where i is the label of the assignment, taken from the order it appeared from 1 to n, and t is the integer time when that assignment was finished.

Example

Input 1
3
4 3 2
2 5
Output 1
Completed assignment 2 at time 5
Completed assignment 3 at time 7
Completed assignment 1 at time 9
  • At time 0, we start assignment 1 (takes 4 units)
  • At time 2, we switch to assignment 2, which takes 3 units (we have completed 2/4 for assignment 1).
  • At time 5, we will switch to assignment 3. which takes 2 units work. We have finished 3/3 for assignment 2, so output it is completed now.
  • At time 7, we will have finished assignment 3. We then switch back to assignment 1.
  • At time 9, we will have finished assignment 1, concluding the problem.
Input 2
4
2 4 3 1
1 6 8
Output 2
Completed assignment 2 at time 5
Completed assignment 1 at time 6
Completed assignment 4 at time 9
Completed assignment 3 at time 10
  • At time 1, we switch to assignment 2. Assignment 1 has 1 work remaining
  • At time 5, we finish assignment 2 and switch back to assignment 1
  • At time 6, we finish assignment 1, we also switch to assignment 3.
  • At time 8, we switch to assignment 4. Assignment 3 has 1 work remaining
  • At time 9, we finish assignment 4, and switch back to assignment 3
  • At time 10, we finish assignment 3

Comments

There are no comments at the moment.