結果

問題 No.1767 BLUE to RED
ユーザー houren
提出日時 2021-11-27 00:08:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 173,016 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-06-29 18:51:57
合計ジャッジ時間 5,084 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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