import java.util.Scanner;
public class MinimumProductFinder {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int[] high = new int[a];
int[] weight = new int[a];
for (int b = 0; b < a; b++) {
high[b] = scanner.nextInt();
}
for (int c = 0; c < a; c++) {
weight[c] = scanner.nextInt();
}
long minProduct = Long.MAX_VALUE;
int bestHigh = 0;
int bestWeight = 0;
for (int d = 0; d < a; d++) {
long currentProduct = (long)high[d] * weight[d];
if (currentProduct < minProduct) {
minProduct = currentProduct;
bestHigh = high[d];
bestWeight = weight[d];
}
}
System.out.println(bestHigh + " " + bestWeight);
scanner.close();
}
}
import java.util.Scanner;
public class MinimumProductFinder {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// --- Input Reading ---
// Read the number of elements/pairs (a)
int a = scanner.nextInt();// Declare and allocate the arrays for high and weight.
// Array size is determined by the input 'a'.
int[] high = new int[a];
int[] weight = new int[a];// Read all 'high' values
for (int b = 0; b < a; b++) {
high[b] = scanner.nextInt();
}// Read all 'weight' values
for (int c = 0; c < a; c++) {
weight[c] = scanner.nextInt();
}// --- Finding the Minimum Product ---
// Initialize variables for tracking the minimum product and the corresponding values.
// The C++ used a very large initial value for mim (10,000,000).
// A safer Java practice is to initialize with the product of the first pair.
// We use 'long' for the product to prevent potential overflow.
long minProduct = Long.MAX_VALUE; // Initialize with the largest possible long value
// Variables to store the 'high' and 'weight' corresponding to the minimum product
int bestHigh = 0;
int bestWeight = 0;// Loop through the arrays to calculate the product and find the minimum
for (int d = 0; d < a; d++) {
// Calculate the current product. Casting to long is crucial to prevent overflow
// before the multiplication, ensuring a correct result for the comparison.
long currentProduct = (long)high[d] * weight[d];// Check if the current product is the new minimum
if (currentProduct < minProduct) {
minProduct = currentProduct;
bestHigh = high[d];
bestWeight = weight[d];
}
}// --- Output ---
// Print the high and weight values of the pair with the minimum product, separated by a space.
// Equivalent to C++'s 'cout << hi << ' ' << wei;'
System.out.println(bestHigh + " " + bestWeight);// Close the scanner
scanner.close();
}
}}
import java.util.Scanner;
public class MinimumProductFinder {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// --- Input Reading ---
// Read the number of elements/pairs (a)
int a = scanner.nextInt();// Declare and allocate the arrays for high and weight.
// Array size is determined by the input 'a'.
int[] high = new int[a];
int[] weight = new int[a];// Read all 'high' values
for (int b = 0; b < a; b++) {
high[b] = scanner.nextInt();
}// Read all 'weight' values
for (int c = 0; c < a; c++) {
weight[c] = scanner.nextInt();
}// --- Finding the Minimum Product ---
// Initialize variables for tracking the minimum product and the corresponding values.
// The C++ used a very large initial value for mim (10,000,000).
// A safer Java practice is to initialize with the product of the first pair.
// We use 'long' for the product to prevent potential overflow.
long minProduct = Long.MAX_VALUE; // Initialize with the largest possible long value
// Variables to store the 'high' and 'weight' corresponding to the minimum product
int bestHigh = 0;
int bestWeight = 0;// Loop through the arrays to calculate the product and find the minimum
for (int d = 0; d < a; d++) {
// Calculate the current product. Casting to long is crucial to prevent overflow
// before the multiplication, ensuring a correct result for the comparison.
long currentProduct = (long)high[d] * weight[d];// Check if the current product is the new minimum
if (currentProduct < minProduct) {
minProduct = currentProduct;
bestHigh = high[d];
bestWeight = weight[d];
}
}// --- Output ---
// Print the high and weight values of the pair with the minimum product, separated by a space.
// Equivalent to C++'s 'cout << hi << ' ' << wei;'
System.out.println(bestHigh + " " + bestWeight);// Close the scanner
scanner.close();
}
}//附上英文註解第一個最後少了一個{
}