結果

問題 No.1767 BLUE to RED
ユーザー CleyLCleyL
提出日時 2023-06-20 13:59:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 15,736 KB
最終ジャッジ日時 2023-09-10 09:36:27
合計ジャッジ時間 6,686 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 101 ms
9,580 KB
testcase_10 AC 128 ms
11,616 KB
testcase_11 AC 108 ms
10,004 KB
testcase_12 AC 100 ms
9,736 KB
testcase_13 AC 141 ms
12,724 KB
testcase_14 AC 176 ms
15,568 KB
testcase_15 AC 177 ms
14,656 KB
testcase_16 AC 177 ms
14,672 KB
testcase_17 AC 176 ms
14,808 KB
testcase_18 AC 177 ms
14,928 KB
testcase_19 AC 176 ms
15,444 KB
testcase_20 AC 175 ms
14,784 KB
testcase_21 AC 177 ms
14,676 KB
testcase_22 AC 178 ms
14,724 KB
testcase_23 AC 178 ms
15,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<long long> A(n),B(m);
  for(int i = 0; n > i; i++)cin>>A[i];
  for(int i = 0; m > i; i++)cin>>B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  A.push_back(100000000001LL);
  vector<long long> C[A.size()];
  int nw = 0;
  for(int i = 0; m > i; i++){
    while(B[i]>A[nw]){
      nw++;
    }
    C[nw].push_back(B[i]);
  }
  long long ans = 0;
  for(int i = 0; n >= i; i++){
    if(C[i].size() == 0)continue;
    if(!i){
      ans += A[i]-C[i][0];
    }else if(i == n){
      ans += C[i][C[i].size()-1]-A[i-1];
    }else{
      long long mx = max(C[i][0]-A[i-1], A[i]-C[i][C[i].size()-1]);
      for(int j = 1; C[i].size() > j; j++){
        mx = max(mx,C[i][j]-C[i][j-1]);
      }
      ans += A[i]-A[i-1]-mx;
    }
  }
  cout << ans << endl;
}
0