結果

問題 No.2248 max(C)-min(C)
ユーザー RedstoneGamer22RedstoneGamer22
提出日時 2023-04-10 22:11:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 611 ms / 3,000 ms
コード長 745 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 206,200 KB
実行使用メモリ 17,392 KB
最終ジャッジ日時 2024-04-16 00:53:49
合計ジャッジ時間 20,086 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 479 ms
15,648 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 611 ms
17,392 KB
testcase_21 AC 557 ms
16,540 KB
testcase_22 AC 312 ms
14,556 KB
testcase_23 AC 185 ms
9,184 KB
testcase_24 AC 66 ms
6,224 KB
testcase_25 AC 500 ms
15,968 KB
testcase_26 AC 426 ms
14,780 KB
testcase_27 AC 499 ms
15,820 KB
testcase_28 AC 34 ms
5,376 KB
testcase_29 AC 445 ms
14,948 KB
testcase_30 AC 158 ms
8,932 KB
testcase_31 AC 605 ms
17,260 KB
testcase_32 AC 76 ms
6,268 KB
testcase_33 AC 131 ms
7,604 KB
testcase_34 AC 582 ms
17,388 KB
testcase_35 AC 575 ms
17,224 KB
testcase_36 AC 568 ms
17,260 KB
testcase_37 AC 239 ms
10,632 KB
testcase_38 AC 511 ms
17,392 KB
testcase_39 AC 504 ms
17,264 KB
testcase_40 AC 502 ms
17,388 KB
testcase_41 AC 394 ms
15,360 KB
testcase_42 AC 497 ms
17,388 KB
testcase_43 AC 418 ms
15,796 KB
testcase_44 AC 497 ms
17,260 KB
testcase_45 AC 356 ms
14,736 KB
testcase_46 AC 161 ms
9,032 KB
testcase_47 AC 523 ms
17,384 KB
testcase_48 AC 346 ms
17,260 KB
testcase_49 AC 493 ms
17,384 KB
testcase_50 AC 486 ms
17,260 KB
testcase_51 AC 488 ms
17,260 KB
testcase_52 AC 483 ms
17,260 KB
testcase_53 AC 59 ms
6,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> a(n); for(auto &e : a) cin >> e;
    vector<int> b(n); for(auto &e : b) cin >> e;

    multiset<int> s;
    vector<pair<int, int>> ev;

    for(int i = 0; i < n; i++) {
        int c = (a[i] + b[i]) / 2;
        if(a[i] > b[i]) swap(a[i], b[i]);

        s.insert(a[i]);
        ev.push_back({a[i], c});
        ev.push_back({c, b[i]});
    }

    #define get_dif (*(s.rbegin()) - *(s.begin()))

    int ans = get_dif;

    sort(ev.begin(), ev.end());
    for(auto e : ev) {
        s.erase(s.lower_bound(e.first));
        s.insert(e.second);

        ans = min(ans, get_dif);
    }

    #undef get_dif

    cout << ans << endl;

    return 0;
}
0