結果
問題 | No.2856 Junk Market Game |
ユーザー |
|
提出日時 | 2024-05-09 23:01:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 627 bytes |
コンパイル時間 | 2,296 ms |
コンパイル使用メモリ | 200,716 KB |
最終ジャッジ日時 | 2025-02-21 12:05:45 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;vector<int> a(n * 2), b(n * 2);for(int i = 0; i < n * 2; i++) cin >> a[i];for(int i = 0; i < n * 2; i++) cin >> b[i];vector<pair<int, int>> p(n * 2);for(int i = 0; i < n * 2; i++) p[i] = {a[i] + b[i], i};sort(p.begin(), p.end());long long ans = 0;for(int i = 0; i < 2 * n; i++){int idx = p[i].second;if(i % 2 == 0){ans += a[idx];}else{ans -= b[idx];}}cout << ans << "\n";}