#line 1 "main.cpp" /** * @title Template */ #include #include #include #include #include #include #include #line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/chmin_chmax.cpp" template constexpr bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template constexpr bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } /** * @title Chmin/Chmax */ #line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp" #line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp" class range { struct iter { std::size_t itr; constexpr iter(std::size_t pos) noexcept: itr(pos) { } constexpr void operator ++ () noexcept { ++itr; } constexpr bool operator != (iter other) const noexcept { return itr != other.itr; } constexpr std::size_t operator * () const noexcept { return itr; } }; struct reviter { std::size_t itr; constexpr reviter(std::size_t pos) noexcept: itr(pos) { } constexpr void operator ++ () noexcept { --itr; } constexpr bool operator != (reviter other) const noexcept { return itr != other.itr; } constexpr std::size_t operator * () const noexcept { return itr; } }; const iter first, last; public: constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { } constexpr iter begin() const noexcept { return first; } constexpr iter end() const noexcept { return last; } constexpr reviter rbegin() const noexcept { return reviter(*last - 1); } constexpr reviter rend() const noexcept { return reviter(*first - 1); } }; /** * @title Range */ #line 16 "main.cpp" using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; int main() { usize N; std::cin >> N; std::vector A(N), B(N); for (auto &x: A) { std::cin >> x; } for (auto &x: B) { std::cin >> x; } i32 max = 0; std::vector order(N); std::iota(order.begin(), order.end(), (usize) 0); do { i32 get = 0; for (auto i: range(0, N)) { i32 dif = A[order[i]] - B[i]; get += std::max(dif, 0); } chmax(max, get); } while (std::next_permutation(order.begin(), order.end())); usize count = 0; std::iota(order.begin(), order.end(), (usize) 0); do { i32 get = 0; for (auto i: range(0, N)) { i32 dif = A[order[i]] - B[i]; get += std::max(dif, 0); } if (get == max) { count += 1; } } while (std::next_permutation(order.begin(), order.end())); std::cout << count << '\n'; return 0; }