-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGambling.cpp
More file actions
59 lines (39 loc) · 774 Bytes
/
Gambling.cpp
File metadata and controls
59 lines (39 loc) · 774 Bytes
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
#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false)
#define boost cin.tie(NULL)
#define endl "\n"
typedef long long int lld;
#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
using namespace std;
int main(){
lld n;
cin>>n;
lld A[n+1],B[n+1];
F(A,n);
F(B,n);
lld sum_a = 0 ;
lld sum_b = 0 ;
sort(A,A+n,greater<lld>());
sort(B,B+n,greater<lld>());
//bool flaga= true;
lld ja= 0;
lld jb= 0;
for(lld i=0;i<n;i++){
if( (ja>=n) || ((jb<n) && A[ja]<B[jb]) )
jb++;
else {
sum_a+= A[ja];
ja++;
}
if( (jb>=n) || ((ja<n) && B[jb]<A[ja]) )
ja++;
else {
sum_b+= B[jb];
jb++;
}
//flaga= !flaga;
}
cout<<(sum_a-sum_b);
return 0;
}