Game of Credit Cards

 

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.

Input

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.

Output

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.

Examples

Input
3
123
321
Output
0
2
Input
2
88
00
Output
2
0

Note

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

 

题意:给定两个数字串,S1 ,S2,Sherlock ,Moriarty 两个人拿数字进行比较,小的一方就要挨打,现在问 Moriarty 挨打的最小次数和 Sherlock 挨打的最多次数

题解:Moriarty 要想挨打最少,那么肯定采取 数字相等 最多或者是 尽可能的比对方数字大 两种策略,

  那么,先从小到大排序,逆向遍历 Sherlock 的数字串,如果 Sherlock 的数字s1【i】不大于Moriarty的数字s2【j】,就证明 Moriarty 不用挨打,那就 J-- 

  最后,J左边的数字,不论哪一个都会比 Moriarty 剩余的数字小,而J从0开始,那么输出 J+1 就可以

  Sherlock 挨打的最多次数,那就从左遍历,每次在S2【j】找比S1【i】大的第一个数,然后计数,并J++,最后输出计数的个数就ok

  

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <map>
 7 #include <set>
 8 #include <list>
 9 #include <deque>
10 #include <queue>
11 #include <stack>
12 #include <cstdlib>
13 #include <cstdio>
14 #include <cmath>
15 #include <iomanip>
16 #define ull unsigned long long
17 #define ll long long
18 #define pb push_back
19 #define all(vc) vc.begin() , vc.end()
20 #define rep(i,start,end) for(int i=start;i<=end;i++)
21 #define per(i,end,start) for(int i=end;i>=start;i--)
22 #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
23 #define lc now<<1
24 #define rc now<<1|1
25 ll read()
26 {
27     ll x=0,f=1;char ch=getchar();
28     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
29     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
30     return x*f;
31 }
32 using namespace std;
33 const int mod = 998244353;
34 const int mxn = 2e5 +7;
35 ll _,n,m,t,k,u,v,ans,cnt,ok,lim,len,tmp;
36 ll  a[mxn] ,inv[mxn],lazy[mxn],id[mxn];
37 string str , s1 ,s2;
38 bool vis[mxn];
39 int main()
40 {
41     while(cin>>n>>s1>>s2)
42     {
43         sort(all(s1));
44         sort(all(s2));
45         int i = n-1,j = n-1 ,ans = 0 ;
46         for(i=n-1;i>=0;i--)
47             if(s1[i]<=s2[j]) j--;
48         cout<<j+1<<endl;
49         for(;i<n && j<n ;i++)
50             if(s1[j]<s2[i]) j++;
51         cout<<j<<endl;
52     }
53 }

 

posted @ 2020-05-11 14:19  __MEET  阅读(185)  评论(0编辑  收藏  举报