This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, m;
std::cin >> n >> m;
std::vector<ll> t(m), a(m);
for (auto &i : t) {
std::cin >> i;
}
for (auto &i : a) {
std::cin >> i;
}
std::vector<std::vector<ll>> adj(n);
std::vector<ll> indeg(n), outdeg(n);
for (ll i = 0; i < n; ++i) {
for (ll j = 0; j < n; ++j) {
if (i == j) {
continue;
}
if (std::abs(a[i] - a[j]) <= std::abs(t[i] - t[j])) {
adj[i].push_back(j);
outdeg[i]++, indeg[j]++;
}
}
}
std::function<ll(ll)> dfs;
dfs = [&](ll node) {
ll ans = 0;
for (auto &i : adj[node]) {
ans += dfs(i);
}
return std::max(ans, 1LL);
};
ll ans = 0;
for (ll i = 0; i < n; ++i) {
if (indeg[i] == 0) {
ans += dfs(i);
}
}
std::cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |