結果
問題 |
No.2856 Junk Market Game
|
ユーザー |
![]() |
提出日時 | 2024-08-25 20:14:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 613 bytes |
コンパイル時間 | 1,911 ms |
コンパイル使用メモリ | 198,248 KB |
最終ジャッジ日時 | 2025-02-24 02:12:03 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector<int> a(2 * n), b(2 * n); for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } for (int i = 0; i < 2 * n; i++) { cin >> b[i]; } vector<int> idx(2 * n); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return a[i] + b[i] < a[j] + b[j]; }); long long ans = 0; for (int i = 0; i < 2 * n; i++) { if (i % 2 == 0) { ans += a[idx[i]]; } else { ans -= b[idx[i]]; } } cout << ans << '\n'; }