CF777B.Game of Credit Cards

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.

Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if n = 3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.

Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.

Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.

第四季之后,夏洛克与莫里亚蒂意识到了彼此之间争斗的愚蠢,于是决定以一种和平的方式——信用卡游戏——继续他们的较量。

该游戏规则如下:每位玩家各带一张自己最喜爱的 nn 位信用卡。随后,双方依次报出各自卡片上的数字(从左到右一位一位地报)。若两人报出的数字不相等,则数字较小者将被另一方用食指在额头上轻弹一下(即“flick”)。例如,若 n=3n = 3,夏洛克的卡号为 123,莫里亚蒂的卡号为 321:第一轮,夏洛克报 1,莫里亚蒂报 3,因此夏洛克被弹一次;第二轮,两人都报 2,无人被弹;第三轮,夏洛克报 3,莫里亚蒂报 1,因此莫里亚蒂被弹一次。

当然,夏洛克会诚实作答,严格按照卡片上数字从左到右的顺序依次报出;而莫里亚蒂作为真正的反派,则计划作弊:他将按某种重新排列的顺序报出自己卡片上的数字(但他不会改变每个数字出现的总次数)。例如,在上述例子中,莫里亚蒂可选择按 1, 2, 3 的顺序报数,从而完全避免被弹;或者按 2, 3, 1 的顺序报数,使夏洛克被弹两次。

你的任务是:

  • 求出莫里亚蒂最少可能被弹的次数(毕竟没人喜欢被弹);
  • 求出夏洛克最多可能被弹的次数。

注意:这两个目标不同,取得各自最优结果所采用的策略也可能不同。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of digits in the cards Sherlock and Moriarty are going to use.

The second line contains n digits — Sherlock's credit card number.

The third line contains n digits — Moriarty's credit card number.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 10001 \leq n \leq 1000)—— 表示福尔摩斯与莫里亚蒂将使用的卡片上的数字位数。

第二行包含 nn 个数字 —— 福尔摩斯的信用卡号。

第三行包含 nn 个数字 —— 莫里亚蒂的信用卡号。

输出格式

First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.

首先输出莫里亚蒂可能受到的最少弹额头次数。然后输出福尔摩斯可能从莫里亚蒂那里获得的最多弹额头次数。

输入输出样例

  • 输入#1

    3
    123
    321

    输出#1

    0
    2
  • 输入#2

    2
    88
    00

    输出#2

    2
    0

说明/提示

First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.

第一个样例在题目描述中已详细说明。在第二个样例中,莫里亚蒂无法避免被弹两次额头。

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

首页