CF 324C. Marina and Vasya

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 2
abc
xyc
output
ayd
input
1 0
c
b
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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值