-
Notifications
You must be signed in to change notification settings - Fork 1
/
1399B.cpp
52 lines (50 loc) · 1.13 KB
/
1399B.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
#include <bits\stdc++.h>
using namespace std;
void readArray(long long arr[], int len)
{
for (int i = 0; i < len; i++)
{
cin >> arr[i];
}
}
int findMin(long long arr[], int len)
{
int min = arr[0];
for (int i = 1; i < len; i++)
{
if (arr[i] < min)
min = arr[i];
}
return min;
}
int main(int argc, char const *argv[])
{
int t;
long long len, count, temp, minA, minB;
cin >> t;
while (t--)
{
count = 0;
cin >> len;
long long a[len];
long long b[len];
readArray(a, len);
readArray(b, len);
minA = findMin(a, len);
minB = findMin(b, len);
for (int i = 0; i < len; i++)
{
if (minA < a[i] && minB < b[i])
{
temp = (a[i] - minA) > (b[i] - minB) ? b[i] - minB : a[i] - minA;
count += abs((a[i] - minA) - (b[i] - minB)) + temp;
}
else if (minA < a[i])
count += a[i] - minA;
else if (minB < b[i])
count += b[i] - minB;
}
cout << count << endl;
}
return 0;
}