CF1426E.Rock, Paper, Scissors

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob have decided to play the game "Rock, Paper, Scissors".

The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied:

  • if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser;
  • if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser;
  • if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser.

Alice and Bob decided to play exactly nn rounds of the game described above. Alice decided to show rock a1a_1 times, show scissors a2a_2 times and show paper a3a_3 times. Bob decided to show rock b1b_1 times, show scissors b2b_2 times and show paper b3b_3 times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that a1+a2+a3=na_1 + a_2 + a_3 = n and b1+b2+b3=nb_1 + b_2 + b_3 = n.

Your task is to find two numbers:

  1. the minimum number of round Alice can win;
  2. the maximum number of rounds Alice can win.

爱丽丝和鲍勃决定玩“石头剪刀布”游戏。

该游戏由若干轮组成,每轮相互独立。在每一轮中,双方同时出示以下三种手势之一:石头、剪刀或布。若双方出示相同的手势,则该轮结果为平局;否则,遵循以下规则:

  • 若一方出示石头,另一方出示剪刀,则出示石头的一方获胜,另一方失败;
  • 若一方出示剪刀,另一方出示布,则出示剪刀的一方获胜,另一方失败;
  • 若一方出示布,另一方出示石头,则出示布的一方获胜,另一方失败。

爱丽丝和鲍勃决定恰好进行 nn 轮上述游戏。爱丽丝决定出示石头 a1a_1 次、剪刀 a2a_2 次、布 a3a_3 次;鲍勃决定出示石头 b1b_1 次、剪刀 b2b_2 次、布 b3b_3 次。但爱丽丝与鲍勃均未确定各自手势的出示顺序。已知 a1+a2+a3=na_1 + a_2 + a_3 = n 且 b1+b2+b3=nb_1 + b_2 + b_3 = n。

你的任务是求出两个数:

  1. 爱丽丝可能获胜的最少轮数;
  2. 爱丽丝可能获胜的最多轮数。

输入格式

The first line of the input contains one integer nn (1≤n≤1091 \le n \le 10^{9}) — the number of rounds.

The second line of the input contains three integers a1,a2,a3a_1, a_2, a_3 (0≤ai≤n0 \le a_i \le n) — the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that a1+a2+a3=na_1 + a_2 + a_3 = n.

The third line of the input contains three integers b1,b2,b3b_1, b_2, b_3 (0≤bj≤n0 \le b_j \le n) — the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that b1+b2+b3=nb_1 + b_2 + b_3 = n.

输入的第一行包含一个整数 nn(1≤n≤1091 \le n \le 10^{9})—— 表示回合数。

输入的第二行包含三个整数 a1,a2,a3a_1, a_2, a_3(0≤ai≤n0 \le a_i \le n)—— 分别表示 Alice 出石头、剪刀和布的次数。保证 a1+a2+a3=na_1 + a_2 + a_3 = n。

输入的第三行包含三个整数 b1,b2,b3b_1, b_2, b_3(0≤bj≤n0 \le b_j \le n)—— 分别表示 Bob 出石头、剪刀和布的次数。保证 b1+b2+b3=nb_1 + b_2 + b_3 = n。

输出格式

Print two integers: the minimum and the maximum number of rounds Alice can win.

输出两个整数:Alice 能获胜的最少轮数和最多轮数。

输入输出样例

  • 输入#1

    2
    0 1 1
    1 1 0

    输出#1

    0 1
  • 输入#2

    15
    5 5 5
    5 5 5

    输出#2

    0 15
  • 输入#3

    3
    0 0 3
    3 0 0

    输出#3

    3 3
  • 输入#4

    686
    479 178 29
    11 145 530

    输出#4

    22 334
  • 输入#5

    319
    10 53 256
    182 103 34

    输出#5

    119 226

说明/提示

In the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors.

In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round.

In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway.

在第一个例子中,如果 Alice 先出剪刀再出布,而 Bob 先出石头再出剪刀,则 Alice 一局都不会赢。在最优情况下,如果 Alice 先出布再出剪刀,而 Bob 先出石头再出剪刀,则 Alice 将赢得一局。

在第二个例子中,如果 Bob 每一轮都出与 Alice 相同的手势,则 Alice 一局都不会赢。

在第三个例子中,Alice 总是出布,而 Bob 总是出石头,因此 Alice 总是赢得全部三局。

输入解题思路,AI测评打分。不知道怎么写?

首页