#include <bits/stdc++.h> #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } const int max_coord = 1000000; class Deliveries { public: Deliveries(); int num_canceled() const; private: std::vector<std::array<int,2>> planes; }; Deliveries::Deliveries(): planes(2*max_coord+1) { int n; std::cin >> n; REP(i, n) { int r,w,t; std::cin >> r >> w >> t; --r; planes[t - w + max_coord][r] += 1; } } int Deliveries::num_canceled() const { int canceled = 0; for (const auto &plane : planes) { canceled += std::min(plane[0], plane[1]); } return canceled; } int main() { init_io(); Deliveries deliveries; std::cout << deliveries.num_canceled() << "\n"; }
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 | #include <bits/stdc++.h> #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } const int max_coord = 1000000; class Deliveries { public: Deliveries(); int num_canceled() const; private: std::vector<std::array<int,2>> planes; }; Deliveries::Deliveries(): planes(2*max_coord+1) { int n; std::cin >> n; REP(i, n) { int r,w,t; std::cin >> r >> w >> t; --r; planes[t - w + max_coord][r] += 1; } } int Deliveries::num_canceled() const { int canceled = 0; for (const auto &plane : planes) { canceled += std::min(plane[0], plane[1]); } return canceled; } int main() { init_io(); Deliveries deliveries; std::cout << deliveries.num_canceled() << "\n"; } |