CF 324C. Marina and Vasya

来源:互联网 发布:在淘宝上买狗安全吗 编辑:程序博客网 时间:2024/06/08 09:09

C. Marina and Vasya
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.

More formally, you are given two strings s1s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print  - 1.

Input

The first line contains two integers n and t (1 ≤ n ≤ 1050 ≤ t ≤ n).

The second line contains string s1 of length n, consisting of lowercase English letters.

The third line contain string s2 of length n, consisting of lowercase English letters.

Output

Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

Examples
input
3 2abcxyc
output
ayd
input
1 0cb
output
-1

#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<queue>using namespace std;const int maxn=100010;char stra[maxn];char strb[maxn];char strc[maxn];int main(){    int n,t,i,j,k,num;    scanf("%d%d",&n,&t);    scanf("%s%s",stra,strb);    int sam=0;    for(i=0;i<n;++i){        if(stra[i]==strb[i])sam++;    }        int a=0,b=0;t=n-t;num=0;        a=min(t,sam);b=min(t,sam);        for(i=0;i<n;++i){            if(stra[i]==strb[i]&&num<t){                strc[i]=stra[i];num++;            }            else if(stra[i]==strb[i]){                for(j=0;j<26;++j){                    if('a'+j!=stra[i]){                        strc[i]='a'+j;break;                    }                }            }            else if(a<t){                strc[i]=stra[i];a++;            }            else if(b<t){                strc[i]=strb[i];b++;            }            else {                for(j=0;j<26;++j){                    if('a'+j!=stra[i]&&'a'+j!=strb[i]){                        strc[i]='a'+j;break;                    }                }            }        }        if(a<t||b<t){            printf("-1\n");        }        else {            strc[n]=0;            printf("%s\n",strc);        }    return 0;}


0 0