公式
B - 村人の畑 / Villagers' Fields 解説 by admin
swe-2-highEditorial
Villager \(i\)’s field area is \(A_i \times B_i\). Read the pairs in order and, whenever the product a * b is strictly larger than the best value seen so far, update best and record the index idx. Because the comparison a * b > best is strict, a later villager with an equal area never replaces an earlier one, so the smallest index among the maximum-area villagers is kept — exactly what the problem requires. The product is at most about \(10^6\), but long long is used for safety.
Each villager takes constant work, so the running time is \(O(N)\). Only a fixed number of variables is stored, giving \(O(1)\) memory beyond input/output — \(O(N)\) if the entire input is counted.