結果

問題 No.2856 Junk Market Game
ユーザー tnakao0123
提出日時 2024-08-29 18:44:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 45,568 KB
最終ジャッジ日時 2025-02-24 02:43:44
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:35:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   for (int i = 0; i < n2; i++) scanf("%d", as + i);
      |                                ~~~~~^~~~~~~~~~~~~~
main.cpp:36:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   for (int i = 0; i < n2; i++) scanf("%d", bs + i);
      |                                ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- 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