Untitled

 avatar
unknown
plain_text
10 months ago
2.3 kB
3
Indexable
#include <bits/stdc++.h>
using namespace std;

#define int long long
void __print(int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \
  cerr << "[" << #x << "] = [";                                                \
  _print(x)
#else
#define debug(x...)
#endif

int length(int y) {
  int len = 0;
  while (y > 0) {
    y /= 10;
    len++;
  }
  return len;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a;
  vector<int> b;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    b.push_back(x);
  }
  // sort arrays a and b
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int ans = 0;
  int ai = n - 1;
  int bi = n - 1;
  while (true) {
    if (a[ai] > b[bi]) {
      a.pop_back();
      a.push_back(length(a[ai]));
      sort(a.begin(), a.end());
      ans++;
    } else if (a[ai] < b[bi]) {
      b.pop_back();
      b.push_back(length(b[bi]));
      sort(b.begin(), b.end());
      ans++;
    } else {
      a.pop_back();
      b.pop_back();
      ai--;
      bi--;
    }
    if (a.size() == 0 || b.size() == 0) {
      break;
    }
  }
  cout << ans << endl;
}

signed main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Editor is loading...
Leave a Comment