結果

問題 No.1597 Matrix Sort
ユーザー kanzakihikarukanzakihikaru
提出日時 2021-07-09 23:42:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 1,500 ms
コード長 1,631 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 170,812 KB
実行使用メモリ 5,556 KB
最終ジャッジ日時 2023-09-14 11:01:16
合計ジャッジ時間 7,802 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 49 ms
5,316 KB
testcase_04 AC 317 ms
5,556 KB
testcase_05 AC 365 ms
5,312 KB
testcase_06 AC 365 ms
5,424 KB
testcase_07 AC 351 ms
5,324 KB
testcase_08 AC 259 ms
5,424 KB
testcase_09 AC 264 ms
5,300 KB
testcase_10 AC 87 ms
5,316 KB
testcase_11 AC 125 ms
5,464 KB
testcase_12 AC 118 ms
5,424 KB
testcase_13 AC 270 ms
5,420 KB
testcase_14 AC 302 ms
5,388 KB
testcase_15 AC 101 ms
5,464 KB
testcase_16 AC 149 ms
5,428 KB
testcase_17 AC 171 ms
5,424 KB
testcase_18 AC 327 ms
5,376 KB
testcase_19 AC 223 ms
5,456 KB
testcase_20 AC 159 ms
5,312 KB
testcase_21 AC 153 ms
5,324 KB
testcase_22 AC 154 ms
5,424 KB
testcase_23 AC 130 ms
5,376 KB
testcase_24 AC 31 ms
5,316 KB
testcase_25 AC 29 ms
5,460 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>

#define rep(i,n) for(ll i=0;i < (n);i++)
#define rep2(i, s, n) for (ll i = (s); i < (n); i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define ff first
#define ss second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll INF=1000000000000000000ll;
const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

ll N, K, P;
vector<ll> A, B;

bool solve(ll now){
  ll t1, t2, t3, cnt = 0;
  rep(i, N){
    t1 = now - A[i]; t2 = P - A[i]; t3 = t1 + P;
    auto itr1 = lower_bound(ALL(B), t1);
    auto itr2 = lower_bound(ALL(B), t2);
    auto itr3 = lower_bound(ALL(B), t3);
    cnt += itr1 - B.begin();
    cnt += (itr3 - B.begin()) - (itr2 - B.begin());
    if(cnt >= K){return true;}
  }
  return false;
}

int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);
  ll tmp; cin >> N >> K >> P;
  rep(i, N){cin >> tmp; A.push_back(tmp);}
  rep(i, N){cin >> tmp; B.push_back(tmp);}
  sort(ALL(A)); sort(ALL(B));

  ll OK = P, NG = -1;
  while(OK - NG > 1){
    ll mid = (OK+NG)/2;
    if(solve(mid)){OK = mid;} else{NG = mid;}
  }
  cout << NG << endl;

  return 0;
}
0