結果

問題 No.2856 Junk Market Game
コンテスト
ユーザー tnakao0123
提出日時 2024-08-29 18:44:22
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 845 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 239 ms
コンパイル使用メモリ 60,688 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2026-07-05 13:47:17
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2856.cc:  No.2856 Junk Market Game - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_N2 = MAX_N * 2;

/* typedef */

using ll = long long;
using pii = pair<int,int>;

/* global variables */

int as[MAX_N2], bs[MAX_N2];
pii ps[MAX_N2];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  int n2 = n * 2;
  for (int i = 0; i < n2; i++) scanf("%d", as + i);
  for (int i = 0; i < n2; i++) scanf("%d", bs + i);
  
  for (int i = 0; i < n2; i++) ps[i] = {as[i] + bs[i], as[i]};
  sort(ps, ps + n2);
  
  ll x = 0, y = 0;
  for (int i = 0; i < n2; i++) {
    if (! (i & 1))
      x += ps[i].second;
    else
      y += ps[i].first - ps[i].second;
  }
  
  printf("%lld\n", x - y);
  
  return 0;
}
0