GlobeX Cup '19 J1 - Chess Master Winnie

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Winnie has become the best person on earth in chess, however she wants to be the best chess player in the universe. Winnie has decided to create a spaceship and participate in an intergalactic chess tournament. She is participating in a tournament with N other aliens. Winnie has a rating in chess, a number that approximates her skill level. Her current rating is M. If Winnie wins a game, she will gain A rating. If Winnie loses, she will lose B rating. Winnie will play C games at this tournament. Each alien is numbered from 1 to N. Winnie will always lose against some alien, but will always win against others. Help Winnie determine her rating after the tournament.

Input Specification

The first line of input will contain 5 integers N, M, A, B, C.

The next line of input will contain N integers that are either 1 or 0. 1 indicates that Winnie can always beat the X_i^\text{th} alien, and 0 indicates that Winnie will always lose against the X_i^\text{th} alien.

The next line of input will contain C integers Y_i. Y_i is the i^\text{th} opponent Winnie will face.

If Winnie is very unlucky, her rating can be negative during and after the tournament.

Output Specification

Output Winnie's rating after the tournament.

Constraints

1 \leq N, M, A, B, C \leq 10^3
1 \le Y_i \le N

Sample Input 1

3 3 3 3 4
1 0 1
3 2 2 1

Sample Output 1

3

Explanation 1

Winnie will win against players 1 and 3, but will lose against player 2 twice. Since she gains the same rating for winning as for losing, her rating will not change and stay at 3.


Comments

There are no comments at the moment.