Mock CCC '20 Contest 1 J4 - Speed Dating

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Jonathan at a table.

Jonathan has decided to attend a speed dating event! The event works by having the participant (Jonathan) rotate through a selection of tables where people will come and sit down. As everyone at the event is on a strict schedule, Jonathan will have 5 seconds of allotted time with each participant.

In the event, there are a total of N participants each with their respective table. Jonathan knows that he should be at the i^{th} participant's table at A_i seconds, stay there for 4 seconds and then leave to the next participant at A_i+5 seconds. Every table is initially empty and the i^{th} participant that Jonathan is meeting will arrive at the table at exactly A_i seconds. Jonathan starts his rotation at 0 seconds and takes B_i seconds to get from one table to the next. If Jonathan does not arrive at a table in time, the participant will leave and go home. If he arrives at an empty table, he will assume he is too late and move on with his schedule.

How many seconds does Jonathan spend with a participant?

Constraints

  • 1 \le N \le 10^4
  • 1 \le A \le 10^6
  • 1 \le B \le 10^2

Input Specification

The first line will contain a single integer N.

The second line will contain N integers, A_i such that A_1,A_2,...A_T where A_i is when Jonathan should be at the i^{th} table.

The third line will contain N integers, B_i such that B_1,B_2,..B_T where B_i is the number of seconds it takes Jonathan to get to the i^{th} table from his previous position.

Output Specification

A single integer representing the total number of seconds Jonathan was with any participant.

Sample Input 1

3
1 7 13
1 1 1

Sample Output 1

15

Sample Input 2

2
1 6
4 2

Sample Output 2

5

Comments

There are no comments at the moment.