In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
Input
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
Output
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
Examples
Input
2
5 7
Output
2 5
Input
3
10 2 8
Output
1 8
Input
6
3 8 2 9 4 14
Output
6 9
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to write solution to problem: second-price auction. Input n, then n distinct integers. Output winner index (the highest price) and the second highest price.
We need to read n and list. Determine index of max value, and the second max. Since all distinct, straightforward.
Edge cases: n up to 1000, values up to 10000.
We'll write code.
But the problem is to produce solution, not just algorithm. The user asked "Write a program that reads...".
We'll provide code in Python or C++? The problem statement seems like from codeforces? Typically solutions in C++/Python. I'll provide Python code.
One approach: create list of (value, index) pairs. Sort descending. Then winner = pairs[0][1], second = pairs[1][0]. Or iterate tracking max and second.
We'll use sorted list for simplicity.
Make sure to output index (1-based). So if we have list indices 0..n-1, index = idx+1.
We'll print f"{winner} {second_price}"
We must ensure correct reading. Use sys.stdin.
I'll provide solution.
But the user may want just solution description? They said "Write a program ...". So likely they expect code.
I'll produce a Python script.
Now, the conversation: we have a system message? The user gave the problem description and examples. So we should output the program.
Thus final answer: Python code.
Also note: they might want to see explanation? Possibly just code.
I'll include brief explanation? Usually in such tasks, we output the code.
Thus final:
python
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
prices = list(map(int, data[1:1+n]))
# find winner (index of max) and second highest price
max_val = -1
max_idx = -1
second_val = -1
for i, p in enumerate(prices):
if p > max_val:
second_val = max_val
max_val = p
max_idx = i
elif p > second_val:
second_val = p
# winner index 1-based
winner = max_idx + 1
print(winner, second_val)
if __name__ == "__main__":
main()
This uses O(n) time. Edge: n >=2, so second_val will be set.
Second: [10,2,8] -> max_val=10 idx=0 -> winner=1, second_val after: when see 2, max unchanged, second maybe 2; then 8 > 2, second becomes 8. So output "1 8". Good.
Third: [3,8,2,9,4,14] -> track: start max=-1 second=-1; p=3 -> max=3 idx=0; second? initially -1 becomes -1? Actually when p > max: second = max_val (which is -1) -> second = -1, then max=3, idx=0. So second becomes -1 (invalid). Then p=8: 8 > 3, so second = max_val =3, max=8, idx=1. second=3. Then p=2: not > max, but > second? 2 > 3? No, second remains 3. Then p=9: 9 > 8, so second = max_val=8, max=9, idx=3. second=8. Then p=4: not > max, 4 > 8? No. Then p=14: 14 > 9, so second = max_val=9, max=14, idx=5. second=9. Output "6 9". Good.
Works.
We'll output code.
Thus final answer. ```python
import sys
def main() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
prices = list(map(int, data[1:1 + n]))
code
max_val = -1
max_idx = -1
second_val = -1
for i, p in enumerate(prices):
if p > max_val:
# previous max becomes the second best candidate
second_val = max_val
max_val = p
max_idx = i
elif p > second_val:
second_val = p
# indices are 1‑based
winner = max_idx + 1
print(winner, second_val)