結果

問題 No.1767 BLUE to RED
ユーザー hourenhouren
提出日時 2021-11-27 00:08:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 172,128 KB
実行使用メモリ 9,376 KB
最終ジャッジ日時 2023-09-12 05:45:02
合計ジャッジ時間 5,798 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 104 ms
6,624 KB
testcase_10 AC 126 ms
7,728 KB
testcase_11 AC 109 ms
7,064 KB
testcase_12 AC 106 ms
6,480 KB
testcase_13 AC 141 ms
8,104 KB
testcase_14 AC 197 ms
9,304 KB
testcase_15 AC 198 ms
8,076 KB
testcase_16 AC 198 ms
8,096 KB
testcase_17 AC 199 ms
9,196 KB
testcase_18 AC 195 ms
8,152 KB
testcase_19 AC 199 ms
9,196 KB
testcase_20 AC 197 ms
9,248 KB
testcase_21 AC 198 ms
9,292 KB
testcase_22 AC 198 ms
9,376 KB
testcase_23 AC 196 ms
9,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,bool>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> ab(n+m+2);
    rep(i,n+m){
        cin >> ab[i].first;
        ab[i].second = (i<n);
    }
    ab[n+m] = make_pair(-100100100100100,true);
    ab[n+m+1] = make_pair(100100100100100,true);
    sort(all(ab));
    ll prev, ans = 0, ma = 0;
    rep(i,n+m+2){
        if(ab[i].second){
            if(ma){
                ma = max(ma, ab[i].first - ab[i-1].first);
                ans += ab[i].first - prev - ma;
                ma = 0;
            }
            prev = ab[i].first;
        }else{
            ma = max(ma, ab[i].first - ab[i-1].first);
        }
    }
    cout << ans << endl;
    return 0;
}
0