Skip to content

Instantly share code, notes, and snippets.

@qjatn0120
Created September 8, 2022 17:17
Show Gist options
  • Save qjatn0120/99eb5160114387d3a49151675e54eafe to your computer and use it in GitHub Desktop.
Save qjatn0120/99eb5160114387d3a49151675e54eafe to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
priority_queue <int> a, b;
int t, n, x;
int f(int val){
int res = 0;
while(val) val /= 10, res++;
return res;
}
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
cin >> t;
while(t--){
cin >> n;
for(int i = 0; i < n; i++){
cin >> x;
a.push(x);
}
for(int i = 0; i < n; i++){
cin >> x;
b.push(x);
}
int ans = 0;
while(!a.empty()){
int val1 = a.top(), val2 = b.top();
a.pop(), b.pop();
if(val1 > val2){
a.push(f(val1));
b.push(val2);
ans++;
}else if(val1 < val2){
a.push(val1);
b.push(f(val2));
ans++;
}
}
cout << ans << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment