LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/7/25 daily

CF 1157F

void solve() {
  int n;
  cin >> n;
  vector<int> a(N);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[x]++;
  }
  int st = 0, ed = 0, ans = 1, cur_len = 0, ans_st = 0;
  for (int i = 1; i < N; ++i) {
    if (st && a[i] < 2) {
      cur_len += a[i];
      if (cur_len >= ans) {
        ans = cur_len;
        ans_st = st;
        ed = i;
      }
      st = 0;
      cur_len = 0;
    } else if (st && a[i] >= 2) {
      cur_len += a[i];
    }
    if (!st && a[i]) {
      st = i;
      cur_len += a[i];
    }
  }
  cout << ans << '\n';
  for (int i = ans_st; i <= ed; ++i) {
    for (int j = 1; j < a[i]; ++j) {
      cout << i << ' ';
    }
  }
  for (int i = ed; i >= ans_st; --i) {
    if (a[i]) {
      cout << i << ' ';
    }
  }
  return;
}

CF 1257E

void solve() {
  int k1, k2, k3, x;
  cin >> k1 >> k2 >> k3;
  int n = k1 + k2 + k3;
  for (int i = 1; i <= k1; ++i) {
    cin >> x;
    a[x] = 1;
  }
  for (int i = 1; i <= k2; ++i) {
    cin >> x;
    a[x] = 2;
  }
  for (int i = 1; i <= k3; ++i) {
    cin >> x;
    a[x] = 3;
  }
  int pre = INT_MIN, ans = INT_MIN, cnt1 = 0, cnt2 = 0, cnt3 = 0;
  for (int i = 0; i <= n; ++i) {
    if (a[i] == 1) {
      ++cnt1;
    } else if (a[i] == 2) {
      ++cnt2;
    } else if (a[i] == 3) {
      ++cnt3;
    }
    pre = max(pre, cnt1 - cnt2);
    ans = max(ans, pre + k3 - cnt3 + cnt2);
  }
  cout << n - ans << '\n'; // n - ans is the answer
  return;
}