結果

問題 No.1767 BLUE to RED
ユーザー umezoumezo
提出日時 2021-11-26 23:55:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 208,876 KB
実行使用メモリ 16,952 KB
最終ジャッジ日時 2023-09-12 05:42:28
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 54 ms
10,068 KB
testcase_10 AC 63 ms
15,244 KB
testcase_11 AC 57 ms
10,380 KB
testcase_12 AC 56 ms
10,592 KB
testcase_13 AC 69 ms
15,380 KB
testcase_14 AC 106 ms
16,380 KB
testcase_15 AC 106 ms
16,752 KB
testcase_16 AC 111 ms
16,840 KB
testcase_17 AC 107 ms
16,952 KB
testcase_18 AC 106 ms
16,240 KB
testcase_19 AC 106 ms
16,432 KB
testcase_20 AC 109 ms
16,584 KB
testcase_21 AC 107 ms
16,560 KB
testcase_22 AC 108 ms
16,444 KB
testcase_23 AC 107 ms
16,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,m;
  cin>>n>>m;
  vector<ll> A(n),B(m);
  rep(i,n) cin>>A[i];
  rep(i,m) cin>>B[i];
  vector<ll> C;
  rep(i,m){
    if(B[i]>A[0] && B[i]<A[n-1]) C.push_back(B[i]);
  }
  ll l=C.size();
  ll ans=0;
  if(B[0]<A[0]) ans+=A[0]-B[0];
  if(B[m-1]>A[n-1]) ans+=B[m-1]-A[n-1];
  
  vector<pair<ll,ll>> P;
  rep(i,n) P.push_back({A[i],0});
  rep(i,l) P.push_back({C[i],1});
  sort(ALL(P));
  
  ll p=P.size();
  ll pre=P[0].first,ma=0;
  for(int i=1;i<p;i++){
    ma=max(ma,P[i].first-P[i-1].first);
    if(P[i].second==0){
      ans+=P[i].first-pre-ma;
      pre=P[i].first;
      ma=0;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}
0