結果

問題 No.1767 BLUE to RED
ユーザー bonKotsubonKotsu
提出日時 2022-07-24 15:30:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 4,171 ms
コンパイル使用メモリ 262,648 KB
実行使用メモリ 14,672 KB
最終ジャッジ日時 2023-09-20 14:54:08
合計ジャッジ時間 10,130 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 105 ms
9,508 KB
testcase_10 AC 134 ms
11,624 KB
testcase_11 AC 116 ms
10,016 KB
testcase_12 AC 104 ms
9,652 KB
testcase_13 AC 146 ms
12,764 KB
testcase_14 AC 185 ms
14,580 KB
testcase_15 AC 185 ms
14,560 KB
testcase_16 AC 184 ms
14,532 KB
testcase_17 AC 184 ms
14,624 KB
testcase_18 AC 185 ms
14,672 KB
testcase_19 AC 184 ms
14,488 KB
testcase_20 AC 185 ms
14,660 KB
testcase_21 AC 185 ms
14,636 KB
testcase_22 AC 187 ms
14,524 KB
testcase_23 AC 185 ms
14,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n+2), b(m);
  const ll INF = 1e18;
  a[0] = -INF;
  a[n+1] = INF;
  rep(i,n) cin >> a[i+1];
  rep(i,m) cin >> b[i];
  vector<ll> g[n+1];
  // b のグループ分け
  rep(i,m) {
    auto num = lower_bound(all(a), b[i]) - a.begin();
    num--;
    g[num].pb(b[i]);
  }
  auto f = [&](ll l ,ll r, vector<ll> v) {
    ll res = r-l;
    ll mx = v[0]-l;
    v.pb(r);
    rep(i,v.size()-1) chmax(mx,v[i+1]-v[i]);
    return res-mx;

  };
  ll ans = 0;
  rep(i,n+1) {
    if (g[i].size()) ans += f(a[i], a[i+1], g[i]);
  }
  cout << ans << endl;



  return 0;
}
0