E. Rock, Paper, Scissors

194 篇文章 1 订阅
71 篇文章 0 订阅

链接:https://codeforces.com/problemset/problem/1426/E

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 a1a1 times, show scissors a2a2 times and show paper a3a3 times. Bob decided to show rock b1b1 times, show scissors b2b2 times and show paper b3b3 times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that a1+a2+a3=na1+a2+a3=n and b1+b2+b3=nb1+b2+b3=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.

Input

The first line of the input contains one integer nn (1≤n≤1091≤n≤109) — the number of rounds.

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

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

Output

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

Examples

input

Copy

2
0 1 1
1 1 0

output

Copy

0 1

input

Copy

15
5 5 5
5 5 5

output

Copy

0 15

input

Copy

3
0 0 3
3 0 0

output

Copy

3 3

input

Copy

686
479 178 29
11 145 530

output

Copy

22 334

input

Copy

319
10 53 256
182 103 34

output

Copy

119 226

Note

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.

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
ll n,a,b,c,d,e,f,max1,min1,k;
int main()
{
	cin>>n>>a>>b>>c>>d>>e>>f;
	max1=0;
	min1=0;
	max1=min(a,e)+min(b,f)+min(c,d);
	min1=max(0ll,max(a-d-f,max(b-e-d,c-f-e)));
	cout<<min1<<" "<<max1<<endl;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值