Untitled
unknown
plain_text
2 years ago
966 B
9
Indexable
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
string a,b;
bool check(string s)
{
for (int i=1;i<s.size();i++)
{
if (s[i] >= s[i-1]) continue;
else return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
freopen("MARBLE.inp", "r", stdin);
freopen("MARBLE.out", "w", stdout);
cin >> n;
for (int i=0;i<n;i++)
{
string x; cin >> x;
a+=x;
}
cin >> m;
for (int i=0;i<m;i++)
{
string x; cin >>x;
b+=x;
}
ll ans = 0;
for (int i=0;i<n;i++)
{
string c = a.substr(0,i+1);
for (int j=m-1;j>=0;j--)
{
string d = b.substr(j,b.size());
string temp = c+d;
if (i == 0 && check(temp) == false) {cout << 0 << " ";return 0;}
else if (check(temp)) ans = max(ans,(ll)temp.size());
}
}
cout << ans;
return 0;
}
Editor is loading...