标签:
Given a sequence of non-negative integers a0,…,an−1, find the maximum pairwise product, that is, the largest integer that can be obtained by multiplying two different elements from the sequence (or, more formally, max0≤i≠j≤n−1aiaj). Different elements here mean ai and ajwith i≠j (it can be the case that ai=aj).
The first line of the input contains an integer n. The next line contains nnon-negative integers a0,…,an−1 (separated by spaces).
2≤n≤2⋅105; 0≤a0,…,an−1≤105.
Output a single number — the maximum pairwise product.
样例 1
输入:
3
1 2 3
输出:
6
样例 2
输入:
10
7 5 14 2 8 8 10 1 2 3
输出:
140
样例 3
输入:
5
4 6 2 6 1
输出:
36
n = int(input()) a = [int(x) for x in input().split()] assert(len(a) == n) curMax=sndMax=0 for idx in range(0, n): if curMax < a[idx]: sndMax = curMax curMax = a[idx] elif sndMax < a[idx]: sndMax=a[idx] print(curMax*sndMax)
标签:
原文地址:http://www.cnblogs.com/dm1299/p/5503315.html