結果

問題 No.2835 Take and Flip
ユーザー vjudge1
提出日時 2024-09-28 16:36:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 405 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 80,576 KB
最終ジャッジ日時 2025-02-24 13:59:19
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using  namespace std;

int n;


int main() {
	cin >> n;
	vector<int>arr(n,0);
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());
	long long x =0, y=0;
	int l, r;
	for ( l = 0, r = n - 1; l < r; l++, r--) {
		x += arr[r];
		y += -arr[l];
	}
	if (l == r) x += arr[r];
	cout << x - y << endl;
	return 0;
	
}
0