結果
問題 | No.2856 Junk Market Game |
ユーザー |
![]() |
提出日時 | 2024-08-25 15:48:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 921 bytes |
コンパイル時間 | 2,117 ms |
コンパイル使用メモリ | 208,340 KB |
最終ジャッジ日時 | 2025-02-24 01:35:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
#include<bits/stdc++.h> using namespace std; int N,A[2000],B[2000]; bool use[2000]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; for(int i=0;i<2*N;i++)cin>>A[i]; for(int i=0;i<2*N;i++)cin>>B[i]; map<int,vector<int>>mp; for(int i=0;i<2*N;i++)mp[A[i]+B[i]].push_back(i); long X=0,Y=0; int t=0; for(auto[sum,V]:mp) { while(V.size()) { if(t==0) { sort(V.begin(),V.end(),[&](int i, int j) { return A[i]>A[j]; }); X+=A[V.back()]; } else { sort(V.begin(),V.end(),[&](int i, int j) { return B[i]>B[j]; }); Y+=B[V.back()]; } V.pop_back(); t^=1; } } cout<<X-Y<<endl; }