結果

問題 No.1597 Matrix Sort
ユーザー emakemak
提出日時 2021-07-09 23:06:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 1,500 ms
コード長 1,319 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 203,720 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-14 10:38:50
合計ジャッジ時間 8,130 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 274 ms
4,568 KB
testcase_04 AC 294 ms
4,888 KB
testcase_05 AC 307 ms
4,616 KB
testcase_06 AC 298 ms
4,660 KB
testcase_07 AC 303 ms
4,716 KB
testcase_08 AC 239 ms
4,756 KB
testcase_09 AC 251 ms
4,580 KB
testcase_10 AC 170 ms
4,624 KB
testcase_11 AC 137 ms
4,568 KB
testcase_12 AC 127 ms
4,668 KB
testcase_13 AC 231 ms
4,560 KB
testcase_14 AC 262 ms
4,572 KB
testcase_15 AC 97 ms
4,568 KB
testcase_16 AC 151 ms
4,664 KB
testcase_17 AC 175 ms
4,684 KB
testcase_18 AC 282 ms
4,784 KB
testcase_19 AC 204 ms
4,584 KB
testcase_20 AC 165 ms
4,564 KB
testcase_21 AC 157 ms
4,572 KB
testcase_22 AC 162 ms
4,660 KB
testcase_23 AC 166 ms
4,676 KB
testcase_24 AC 32 ms
4,568 KB
testcase_25 AC 31 ms
4,760 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n;
    ll k, p;
    cin >> n >> k >> p;
    vector<ll> a(n), b(n);
    cin >> a >> b;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    ll lb=-1, ub=p;
    while(ub-lb>1){
        ll x = (ub+lb)/2;
        
        ll m = 0;
        for(int i=0; i<n; i++){
            m += lower_bound(a.begin(), a.end(), x-b[i]+1) - a.begin();
            m +=  lower_bound(a.begin(), a.end(), p+x-b[i]+1) - lower_bound(a.begin(), a.end(), p-b[i]);
        }

        if(m<k) {
            lb = x;
        } else {
            ub = x;
        }
    }

    cout << ub << endl;
    return 0;
}
0