GlobeX Cup '19 J1 - Chess Master Winnie

View as PDF

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 other aliens. Winnie has a rating in chess, a number that approximates her skill level. Her current rating is . If Winnie wins a game, she will gain rating. If Winnie loses, she will lose rating. Winnie will play games at this tournament. Each alien is numbered from to . 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 integers , , , , .

The next line of input will contain integers that are either 1 or 0. 1 indicates that Winnie can always beat the alien, and 0 indicates that Winnie will always lose against the alien.

The next line of input will contain integers . is the 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.

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.