結果

問題 No.3436 [Cherry 8th Tune B] この夏に何が起こるかな?
コンテスト
ユーザー areik
提出日時 2026-01-23 22:02:43
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 740 ms / 4,000 ms
コード長 2,662 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,312 ms
コンパイル使用メモリ 290,248 KB
実行使用メモリ 16,276 KB
最終ジャッジ日時 2026-01-23 22:03:13
合計ジャッジ時間 28,277 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;

using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using f64 = double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint;

void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  _main();
}

void _main() {
  i64 tt;
  cin >> tt;
  for (;tt--;) {
    i64 n, m, k, p;
    cin >> n >> m >> k >> p;
    vector<el> a(n), b(m);
    vector<vector<el>> v1(k), v2(k);
    vector<i64> s(k);
    for (i64 i = 0; i < n; i++) {
      cin >> get<0>(a[i]);
    }
    for (i64 i = 0; i < n; i++) {
      get<2>(a[i]) = i;
      cin >> get<1>(a[i]);
      get<1>(a[i])--;
      v1[get<1>(a[i])].push_back(a[i]);
    }
    for (i64 i = 0; i < m; i++) {
      cin >> get<0>(b[i]);
    }
    for (i64 i = 0; i < m; i++) {
      get<2>(b[i]) = i;
      cin >> get<1>(b[i]);
      get<1>(b[i])--;
      v2[get<1>(b[i])].push_back(b[i]);
    }
    for (i64 i = 0; i < k; i++) {
      cin >> s[i];
    }
    for (i64 i = 0; i < k; i++) {
      sort(v1[i].begin(), v1[i].end());
      sort(v2[i].begin(), v2[i].end());
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    i64 l = -1, r = 1e18;
    while (r - l > 1) {
      i64 mid = (l + r) / 2;
      i64 cnt = 0;
      for (i64 i = 0; i < n; i++) {
        auto [x, c, id] = a[i];
        {
          i64 j = lower_bound(b.begin(), b.end(), (el){mid - x + 1, 0, 0}) - b.begin();
          j -= lower_bound(v2[c].begin(), v2[c].end(), (el){mid - x + 1, 0, 0}) - v2[c].begin();
          cnt += j;
        }
        {
          i64 j = lower_bound(v2[c].begin(), v2[c].end(), (el){mid - x + s[c] + 1, 0, 0}) - v2[c].begin();
          cnt += j;
        }
      }
      if (cnt >= p) r = mid;
      else l = mid;
    }
    i64 ans1 = -1, ans2 = -1;
    for (i64 i = 0; i < n; i++) {
      auto [x, c, id] = a[i];
      {
        i64 j = lower_bound(b.begin(), b.end(), (el){r - x, 0, 0}) - b.begin();
        i64 k = lower_bound(b.begin(), b.end(), (el){r - x + 1, 0, 0}) - b.begin();
        if (j != k) {
          auto [y1, d1, jd1] = b[j];
          auto [y2, d2, jd2] = b[k - 1];
          if (c != d1) {
            ans1 = id, ans2 = jd1;
          } else if (c != d2) {
            ans1 = id, ans2 = jd2;
          }
        }
      }
      {
        i64 j = lower_bound(v2[c].begin(), v2[c].end(), (el){r - x + s[c], 0, 0}) - v2[c].begin();
        if (j < v2[c].size() && get<0>(v2[c][j]) == r - x + s[c]) {
          ans1 = id, ans2 = get<2>(v2[c][j]);
        }
      }
    }
    cout << ans1 + 1 << " " << ans2 + 1 << "\n";
  }
}
0