-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgambling.cpp
65 lines (50 loc) · 1.17 KB
/
gambling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <queue>
using namespace std;
/*
* http://codeforces.com/contest/1038/problem/C
*/
long long sumA = 0, sumB = 0, sumListA = 0, sumListB = 0;
priority_queue<long long> listA, listB;
int main(){
int n;
cin >> n;
long long temp;
for(int i =0; i < n; i++){
cin >> temp;
sumListA +=temp;
listA.push(temp);
}
for(int i =0; i < n; i++){
cin >> temp;
sumListB+= temp;
listB.push(temp);
}
for(int i =0; i < 2*n; i++){
if(!listA.empty() && !listB.empty()){
if(listA.top() >= listB.top()){
if(i%2 == 0){
sumA+= listA.top();
}
listA.pop();
}else{
if(i%2 !=0){
sumB+= listB.top();
}
listB.pop();
}
}else if(!listA.empty()){
if(i%2 == 0){
sumA+= listA.top();
}
listA.pop();
}else{
if(i%2!=0){
sumB+=listB.top();
}
listB.pop();
}
}
cout << sumA - sumB << endl;
return 0;
}