# Problem: RPS

Want to try solving this problem? You can submit your code online if you log in or register.

## RPS

Input File: rpsin.txt
Output File: rpsout.txt
Time Limit: 1 second
Memory Limit: 1 GB

C Rock. Paper. Scissors. The rules are simple. The game is contested by two people over N rounds. During each round, you and your opponent simultaneously throw either Rock, Paper or Scissors. Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. If your throw beats your opponent’s, you gain one point. Conversely, if their throw beats yours, you lose one point.

Your opponent is very predictable. You know that they will throw Rock in the first Ra rounds, throw Paper in the next Pa rounds, then finally throw Scissors in the last Sa rounds, where Ra + Pa + Sa = N.

You will throw Rock in Rb rounds, Paper in Pb rounds, and Scissors in Sb rounds, where Rb + Pb + Sb = N. However, as you are an experienced player, you may throw these in any order you like.

At the beginning of the game, you start with 0 points. What is the maximum number of points you can finish with?

### Input

• The first line of input contains a single integer N, the number of rounds.
• The second line of input contains three space-separated integers: Ra, Pa and Sa.
• The third line of input contains three space-separated integers: Rb, Pb and Sb.

### Output

Your program should output a single integer: the maximum number of points you could score after all N rounds have been played. Note that this number may be positive, negative, or zero.

```5
2 2 1
1 3 1
```

```4
```

```4
1 2 1
4 0 0
```

```-1
```

```1
0 0 1
0 0 1
```

```0
```

### Explanation

In the first sample input, there are N = 5 rounds, where your opponent will throw Rock twice, then Paper twice, then Scissors once. You must throw Rock once, Paper three times and Scissors once. Here is one way you can order your throws:

1 Paper Rock Win! +1
2 Paper Rock Win! +1
3 Scissors Paper Win! +1
4 Paper Paper Draw 0
5 Rock Scissors Win! +1

This results in a total of 4 points, which is the maximum possible.

In the second sample input, there are N = 4 rounds, where your opponent will throw Rock once, then Paper twice, then Scissors once. You must throw Rock four times, and cannot throw Paper or Scissors. There is only one way you can order your throws:

1 Rock Rock Draw 0
2 Rock Paper Lose... -1
4 Rock Paper Lose... -1
4 Rock Scissors Win! +1

This results in a total of -1 points, which is the maximum possible. Note that the answer can be negative!

In the third sample input, there is N = 1 round. Your opponent will throw Scissors in this one round, and you will also throw Scissors. This results in a draw, so you will score 0 points.

For all test cases:

• 1 ≤ N ≤ 5000.
• 0 ≤ Ra, Pa, Sa, Rb, Pb, Sb.
• Ra + Pa + Sa = N (that is, your opponent makes exactly N throws).
• Rb + Pb + Sb = N (that is, you make exactly N throws).

Furthermore:

• For Subtask 1 (10 marks), N = 1. Sample Input 3 is an example of a case that could be in this subtask.

Hint: There is only one round, so all you need to do is check whether your throw wins, loses, or draws against your opponent, and output 1, -1 or 0 respectively.

• For Subtask 2 (25 marks), you only throw Rock. More formally, Rb = N, Pb = 0, and Sb = 0. Sample Input 2 is an example of a case that could be in this subtask.

Hint: Since you’re only throwing Rock each time, you just need to check which of your opponent’s throws wins, loses or draws against Rock, and count the results appropriately.

• For Subtask 3 (25 marks), your opponent only throws Rock. More formally, Ra = N, Pa = 0, and Sa = 0.

Hint: The solution to this subtask is quite similar to subtask 2.

• For Subtask 4 (20 marks), neither you nor your opponent throws Scissors. More formally, Sa = 0 and Sb = 0.

Hint: Paper will never lose, since no one ever throws Scissors. Likewise, Rock will never win.

• For Subtask 5 (20 marks), no further constraints apply.

Hint: Win as many rounds as you can! Then try to draw the rest, though sometimes, you can’t avoid losing.

Privacy statement
`Page generated:  1 December 2021, 11:41am AEDT`