-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1324D.cpp
More file actions
67 lines (60 loc) · 1.29 KB
/
Copy path1324D.cpp
File metadata and controls
67 lines (60 loc) · 1.29 KB
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
66
67
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll hihi(const std::vector<ll> &sortedVector, ll target)
{
auto it = std::lower_bound(sortedVector.begin(), sortedVector.end(), target);
if (it != sortedVector.end())
{
return std::distance(sortedVector.begin(), it);
}
return -1;
}
void solve()
{
ll n, i, ind = 0, ans = 0, y = 0;
cin >> n;
ll a[n], b[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
vector<ll> z;
for (int i = 0; i < n; i++)
z.push_back(a[i] - b[i]);
sort(z.begin(), z.end());
for (int i = 0; i < n - 1; i++)
{
if (z[i] < 0)
{
if (hihi(z, -z[i] + 1) != -1)
{
y = hihi(z, -z[i] + 1);
ans += (n - y);
}
}
else if (z[i] == 0)
{
if (hihi(z, 1) != -1)
{
y = hihi(z, 1);
ans += (n - y);
}
}
else if (z[i] > 0)
{
ind = n - i;
break;
}
}
if (ind > 0)
ans += ((ind * (ind - 1)) / 2);
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}