#P1423. F. AKIE's Penalty
F. AKIE's Penalty
题目描述
Have you ever heard of the ACM penalty time rules? Yes, that's exactly the rule for the competition you're in right now. Your total penalty time is the sum of the penalty time of your wrong submissions for each question plus the time when you pass each question. The penalty time for each wrong submission is .
Formally, there are questions in a contest that AKIE participate. Let be equal to the number of her submissions for the - problem and be equal to the time when AKIE passed the problem. Besides,
-
means she passed the - question at the last submission of the submissions (and the former submissions are wrong).
-
means she didn't pass the - question.
Now, give you a list of the number of AKIE's submissions and her passing time for each question. Please help AKIE calculate her total penalty time.
输入格式
The first line input a number ,
The second line input N numbers of , representing the number of submissions for each question.
The third line input N numbers of , if , it means the passing time for the - question, else, if , it means AKIE didn't pass tht - question.
are all integers.
It's guaranteed that if AKIE passed a question, there's at least one submission of this question.
Note that, AKIE's passing time for a question may be , because her coding ability is outstanding.
输出格式
Only a number representing AKIE's total penalty time.
样例
5
1 2 3 4 5
-1 0 20 30 40
290