#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int n; int64_t A; IN(n, A); A *= 2; vector X(n), Y(n), V(n); for (int i : Rep(0, n)) { IN(X[i], Y[i], V[i]); X[i] *= 2, Y[i] *= 2; } vector Ux(n), Uy(n); for (int i : Rep(0, n)) { Ux[i] = V[i] < 0 ? X[i] - A - 1 : X[i]; Uy[i] = V[i] < 0 ? Y[i] - A - 1 : Y[i]; } ranges::sort(Ux); ranges::sort(Uy); vector>> events(n + 1); for (int i : Rep(0, n)) { // [X[i] - A, X[i] + 1) int lx = int(ranges::lower_bound(Ux, X[i] - A) - Ux.begin()); int rx = int(ranges::lower_bound(Ux, X[i] + 1) - Ux.begin()); int ly = int(ranges::lower_bound(Uy, Y[i] - A) - Uy.begin()); int ry = int(ranges::lower_bound(Uy, Y[i] + 1) - Uy.begin()); events[lx].emplace_back(ly, ry, V[i]); events[rx].emplace_back(ly, ry, -V[i]); } int64_t ans = 0; vector f(n); for (int x : Rep1(0, n)) { for (auto [l, r, v] : events[x]) { for (int i : Rep(l, r)) { f[i] += v; } } if (SetMax(ans, ranges::max(f))) { } } OUT(ans); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); } #elif __INCLUDE_LEVEL__ == 1 #include #include template concept MyRange = std::ranges::range && !std::convertible_to; template concept MyTuple = std::__is_tuple_like::value && !MyRange; namespace std { istream& operator>>(istream& is, MyRange auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, MyTuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, MyRange auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, MyTuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define LAMBDA2(x, y, ...) ([&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; }) #define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__) #define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__) #define SetMax(...) LAMBDA2(x, y, x < y && (x = y, 1))(__VA_ARGS__) #define IN(...) (cin >> forward_as_tuple(__VA_ARGS__)) #define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n') #endif // __INCLUDE_LEVEL__ == 1