#include <iostream> #include <vector> #include <set> #include <tuple> #include <algorithm> int main() { int n; int result= 0; std::cin >> n; std::set<std::tuple<int, int, int>> s; std::vector<int> poziome(2000001); std::vector<int> pionowe(2000001); for (int i = 0; i < n; ++i) { int type, distance, time; std::cin >> type >> distance >> time; if (type == 1) ++poziome[1000000 + time - distance]; else ++pionowe[1000000 + time - distance]; } for (int i = 0; i < 2000001; ++i) { result += std::min(poziome[i], pionowe[i]); } std::cout << result; }
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 | #include <iostream> #include <vector> #include <set> #include <tuple> #include <algorithm> int main() { int n; int result= 0; std::cin >> n; std::set<std::tuple<int, int, int>> s; std::vector<int> poziome(2000001); std::vector<int> pionowe(2000001); for (int i = 0; i < n; ++i) { int type, distance, time; std::cin >> type >> distance >> time; if (type == 1) ++poziome[1000000 + time - distance]; else ++pionowe[1000000 + time - distance]; } for (int i = 0; i < 2000001; ++i) { result += std::min(poziome[i], pionowe[i]); } std::cout << result; } |