def solve(b1,b2):
if len(b1)!=len(b2):
return -1
for i in b1:
if not i in "0123456789":
return -1
for i in b2:
if not i in "0123456789":
return -1
v1=[int(i) for i in b1]
v2=[int(i) for i in b2]
v1.sort()
v2.sort()
a,b=0,0
tmp=0
ln=len(b1)
ans=""
while b<ln:
if v1[a]>v2[b]:
tmp+=1
else:
a+=1
b+=1
ans+=str(tmp)+"\n"
a,b=0,0
tmp=0
ln=len(v1)
while a<ln:
while b<ln and v1[a]>=v2[b]:
b+=1
if b<ln:
tmp+=1
b+=1
a+=1
ans+=str(tmp)
return ans
def doc(lst):
fn=[]
for i in lst:
b1,b2=i[0],i[1]
fn.append(solve(b1,b2))
return fn
n=int(input())
b1=input()
b2=input()
print(solve(b1,b2))
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n;
char a[1005];
char b[1005];
while(scanf("%d",&n)!=EOF)
{
scanf("%s%s",a,b);
sort(a,a+n);
sort(b,b+n);
int x=0;
int y=0;
for(int i=0,j=0;j<n;j++)
{
if(b[j]>=a[i]) i++;
else x++;
}
for(int i=n-1,j=n-1;i>=0;i--)
{
if(b[j]>a[i])
{
j--;
y++;
}
}
printf("%d\n%d\n",x,y);
}
return 0;
}
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |