Cramming Assignments
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 , the number of assignments, which are labelled
through
.
The next line contains space-separated integers
, the amount of time each assignment takes to complete.
The next line contains unique space-separated integers
. You start working on the first assignment at
, and then you remember each of the following assignments at each of
, interrupting what your were previously working on. Since there are
assignment lengths and
interruption times, the first
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 at time
" where
is the label of the assignment, taken from the order it appeared from
to
, and
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
, we start assignment 1 (takes 4 units)
- At time
, we switch to assignment 2, which takes 3 units (we have completed 2/4 for assignment 1).
- At time
, 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
, we will have finished assignment 3. We then switch back to assignment 1.
- At time
, 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
, we switch to assignment 2. Assignment 1 has 1 work remaining
- At time
, we finish assignment 2 and switch back to assignment 1
- At time
, we finish assignment 1, we also switch to assignment 3.
- At time
, we switch to assignment 4. Assignment 3 has 1 work remaining
- At time
, we finish assignment 4, and switch back to assignment 3
- At time
, we finish assignment 3
Comments