|
|
вернуться в форумTest#4 What's the test#4? I'm sure my solution is correct: #include <algorithm> #include <array> #include <iostream> #include <limits> uint32_t *arr_n; uint32_t *arr_m; int n, m; uint64_t max_sum = 0; uint32_t min_popularity = std::numeric_limits<uint32_t>::max(); void find_most_popular_route(int i, int j, uint64_t sum, uint32_t cur_min) { if (i == n - 1 && j == m - 1) { if (sum > max_sum) { max_sum = sum; min_popularity = cur_min; } return; } if (i < n - 1) { find_most_popular_route(i + 1, j, sum + arr_m[j], std::min(cur_min, arr_m[j])); } if (j < m - 1) { find_most_popular_route(i, j + 1, sum + arr_n[i], std::min(cur_min, arr_n[i])); } } int main() { std::cin >> n >> m; if (n > 100000 || n < 2 || m > 100000 || m < 2) return 0; arr_n = new uint32_t[n]; for (int i = 0; i < n; i++) { std::cin >> arr_n[i]; } arr_m = new uint32_t[m]; for (int i = 0; i < m; i++) { std::cin >> arr_m[i]; } std::cout << std::endl << std::endl; find_most_popular_route(0, 0, 0, min_popularity); std::cout << min_popularity << std::endl; // std::cout << max_sum << std::endl; delete[] arr_n; delete[] arr_m; return 0; } |
|
|