Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n, m;
- cin>>n>>m;
- string a, b;
- cin>>a>>b;
- int ans = 1e9;
- for(int i=0; i+m<=n; i++)
- {
- int x = 0;
- for(int j=0; j<m; j++)
- x += min({abs(a[i+j]-b[j]), '9'+1-b[j]+a[i+j]-'0', '9'+1+b[j]-a[i+j]-'0'});
- ans = min(ans, x);
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment