eolymp
bolt
Try our new interface for solving problems
Problems

Minimaximal matching

Minimaximal matching

Given the complete bipartite graph. Each part of this graph has \textbf{N} vertices, i.e. the graph is balanced. An integer number (called a weight) assigns to each vertex. The weight of the edge is defined as a product of weights of vertices which connected by this edge. Is is well known, a matching in a graph is a set of edges without common vertices. A matching is perfect, if it covers all vertices of a graph, i.e. each graph vertex is incident to some edge of matching. Your task is to find a perfect minimaximal matching, i.e. such matching, that maximal weight of matching edges would be minimal. (as less as possible). \InputFile The first line of the input file contains integer number \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{10^5}). The second line consist of \textbf{N} integer numbers, not exceeded \textbf{10^9} by absolute value. The \textbf{i}-th number in line denotes a weight of \textbf{i}-th vertex of first part of a graph. In the third line, weights of vertices of second part are presented. Vertices of each part have numbers from \textbf{1} to \textbf{N}. \OutputFile On the first line of output file output the weight of perfect minimaximal matching, i.e. the maximal weight of its edges. The second line should contains a description of this matching in the form of \textbf{N} integer numbers. \textbf{i}-th number denotes a number of vectex in second part, which connected with \textbf{i}-th vertex in first part by a matching edge.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
3
1 2 3
9 10 11
Output example #1
27
3 2 1
Author В.Неспирный
Source Зимние сборы в Харькове 2010 День 1