#include #include #include #include typedef struct { int id; int lat; int lon; int height; int points; } city; struct city_comp { bool operator()(const city& c1, const city& c2) { return c1.height < c2.height; } }; bool diff_less_than(int a, int b, int d) { if(a - b > d) return false; if(b - a > d) return false; return true; } int main() { // Parse input unsigned n; int x, y; std::cin >> n >> x >> y; std::vector data; data.reserve(n); data.push_back({0, 0, 0, 0, 0}); std::vector> graph(n+2, std::list()); for(int i=1; i<=n; ++i) { int l1, l2, h, p; std::cin >> l1 >> l2 >> h >> p; data.push_back({i, l1, l2, h, p}); graph[0].push_back(i); for(int j=1; j values; values.reserve(n+2); values.push_back(0); for(unsigned i=1; i<=n; ++i) values.push_back(data[i].points); values.push_back(0); std::sort(data.begin(), data.end(), city_comp()); for(unsigned lowest=1; lowest<=n; ++lowest) { int city_id = data[lowest].id; for(const int& neighbour : graph[city_id]) { if(values[neighbour] < values[city_id] + data[neighbour].points) values[neighbour] = values[city_id] + data[neighbour].points; } } std::cout << values[n+1] << std::endl; return 0; }