#include <algorithm> #include <cassert> #include <iostream> #include <vector> #include <string> #include <memory> #include <cassert> #include <cstdio> #include <stdexcept> #include <iterator> #include <type_traits> #include <unordered_map> using ull = unsigned long long; using ll = long long; std::unordered_map<ll, ll> left, bottom; int main() { std::ios::sync_with_stdio(false); ll n, r, w, t; std::cin >> n; for(int i = 0; i < n; ++i) { std::cin >> r >> w >> t; if(r == 1) ++bottom[w - t]; else ++left[w - t]; } ll result = 0; for(auto& bottom_car : bottom) { auto left_car = left.find(bottom_car.first); if(left_car != left.end()) { if(left_car->second > bottom_car.second) { result += bottom_car.second; bottom_car.second = 0; } else if(left_car->second <= bottom_car.second) { result += left_car->second; left_car->second = 0; } } } std::cout << result; return 0; }
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 45 46 47 48 49 50 51 52 53 54 55 | #include <algorithm> #include <cassert> #include <iostream> #include <vector> #include <string> #include <memory> #include <cassert> #include <cstdio> #include <stdexcept> #include <iterator> #include <type_traits> #include <unordered_map> using ull = unsigned long long; using ll = long long; std::unordered_map<ll, ll> left, bottom; int main() { std::ios::sync_with_stdio(false); ll n, r, w, t; std::cin >> n; for(int i = 0; i < n; ++i) { std::cin >> r >> w >> t; if(r == 1) ++bottom[w - t]; else ++left[w - t]; } ll result = 0; for(auto& bottom_car : bottom) { auto left_car = left.find(bottom_car.first); if(left_car != left.end()) { if(left_car->second > bottom_car.second) { result += bottom_car.second; bottom_car.second = 0; } else if(left_car->second <= bottom_car.second) { result += left_car->second; left_car->second = 0; } } } std::cout << result; return 0; } |