-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf_1009d.cpp
More file actions
53 lines (40 loc) · 1.15 KB
/
cf_1009d.cpp
File metadata and controls
53 lines (40 loc) · 1.15 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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> centers(n);
for(int i = 0; i < n; ++i) {
cin >> centers[i];
}
vector<int> radii(n);
for(int i = 0; i < n; ++i) {
cin >> radii[i];
}
// (x - x_i)^2 + y^2 <= r^2
// y^2 <= r^2 - (x - x_i)^2
// -sqrt(r^2 - (x - x_i)^2) <= y <= sqrt(r^2 - (x - x_i)^2)
map<long long, long long> cnt;
for (int i = 0; i < n; ++i) {
long long x_i = centers[i];
long long r_i = radii[i];
for (long long x = x_i - r_i; x <= x_i + r_i; ++x) {
if ((x - x_i) * (x - x_i) > r_i * r_i) {
continue;
}
long long a = sqrt(r_i * r_i - (x - x_i) * (x - x_i));
cnt[x] = max(cnt[x], 2LL*a+1);
}
}
long long ans = 0;
for (auto [x, c] : cnt) {
ans += c;
}
cout << ans << '\n';
}
return 0;
}