結果

問題 No.2835 Take and Flip
ユーザー tu su
提出日時 2024-08-21 06:44:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 4,913 ms
コンパイル使用メモリ 277,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-21 06:44:32
合計ジャッジ時間 8,043 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define int long long
typedef long long ll;
void solved() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int sum1 = 0, sum2 = 0;
  for (int i = 1, j = n; i < j; i++, j--) {
    sum1 += a[j];
    sum2 -= a[i];
  }
  if (n & 1) sum1 += a[(n + 1) / 2];
  cout << sum1 - sum2 << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  /* int t = 1;
   cin >> t;
   while (t--)*/
  solved();

  return 0;
}
0