Array Modification
Practice
4 (6 votes)
Algorithms
Easy
Greedy algorithms
Problem
65% Success 3350 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) of \(N\) integers. For every index \(i\) of the array \(A\), you need to select an index \(j\)  such that \(j \neq i \) and the product of \(A[i]\) and \(A[j]\) is maximum for that \(i\) . Finally, you need to print the sum of \(A[i] * A[j]\) for all the indices \(i\) . Since this sum can be large, you need to print it to the modulo \(10^9 + 7\).
Note: Please refer to the sample explanation section.

Input format

  • First line: Integer \(N\) denoting the number of elements in the array \(A\) 
  • Next line: \(N\) space-separated integers denoting the elements of the array \(A\)


Output format

Print the required sum to the modulo \(10^9+7\)

Constraints
\(2 \le N \le 10^5 \)

\(-10^{18} \le A[i] \le 10^{18}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
43 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Points:10
49 votes
Tags:
Ad-HocVery-EasySimple-math
Points:20
10 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsImplementationString Manipulation