Created
March 18, 2025 05:14
-
-
Save aadishv/e379b97abca6f324e018afde4ca0d694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| typedef long long ll; | |
| struct Garden { | |
| ll x, y, t; | |
| ll dist(Garden to) { | |
| return abs(to.x - x)+abs(to.y - y); | |
| } | |
| bool reachable(Garden to) { | |
| return dist(to) <= abs(to.t - t); | |
| } | |
| }; | |
| int main() { | |
| ll ngardens, ncows; | |
| cin >> ngardens >> ncows; | |
| map<ll, Garden> gardens = {}; | |
| set<ll> times = {}; | |
| for (ll i = 0; i < ngardens; i++) { | |
| ll x, y, t; | |
| cin >> x >> y >> t; | |
| gardens[t] = {x,y,t}; | |
| times.insert(t); | |
| } | |
| ll total = 0; | |
| for (ll i = 0; i < ncows; i++) { | |
| ll x, y, t; | |
| cin >> x >> y >> t; | |
| auto g = Garden {x,y,t}; | |
| bool good; | |
| auto bound = times.lower_bound(t); | |
| if (bound == times.begin()) { | |
| good = g.reachable(gardens[*bound]); | |
| } else if (bound == times.end()) { | |
| good = g.reachable(gardens[*prev(bound)]); | |
| } else { | |
| ll second = *bound; | |
| ll first = *prev(bound); | |
| good = g.reachable(gardens[first]) && g.reachable(gardens[second]); | |
| } | |
| total += !good; | |
| } | |
| cout << total << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment