LA 3716

来源:互联网 发布:nginx中文 编辑:程序博客网 时间:2024/06/05 18:49
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;struct node{int lo,v;}G[150005];bool cmp(const node &a,const node &b){if(a.v==b.v)return a.lo<b.lo;elsereturn a.v>b.v;}char str1[150050],str2[150050];int main(){int n,p;while(~scanf("%d%d",&n,&p)&&(n+p)){scanf("%s",str1);scanf("%s",str2);int t=0,res=0;G[0].lo=0,G[0].v=0;for(int i=1;i<=n;i++){if(str1[i-1]!=str2[i-1])t++;    G[i].v=100*t-i*p;G[i].lo=i;}sort(G,G+1+n,cmp);int lo=G[0].lo;for(int i=1;i<=n;i++){if(lo<G[i].lo)res=max(res,G[i].lo-lo);elselo=G[i].lo;}if(res)printf("%d\n",res);elseprintf("No solution.\n");}}

原创粉丝点击