結果
| 問題 |
No.2835 Take and Flip
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-28 15:36:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 646 bytes |
| コンパイル時間 | 2,623 ms |
| コンパイル使用メモリ | 251,148 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-09-28 15:36:46 |
| 合計ジャッジ時間 | 4,214 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
#define int long long
void solve(){
int cnt=0;
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n;i++){
cin >> a[i];
}
sort(a.begin(), a.end());
int l = 0, r = n - 1;
int x = 0, y = 0;
while(cnt<n){
if(cnt%2==0){
x += a[r--];
}
else if(cnt&1){
y += -1ll*a[l++];
}
cnt++;
}
cout << x - y << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
vjudge1