Thursday, June 16, 2016

GeeksForGeeks Challenges


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<vector>
using namespace std;

int main()
{
    //code
    auto t = 0;
    std::cin >> t;

    while (t--)
    {
        auto n = 0;
        std::cin >> n;

        std::vector<int> v;
        
        while (n--)
        {
            auto x = 0;
            
            std::cin >> x;

            v.push_back(x);
        }

        auto max1 = 0;
        auto max2 = 0;
        for (size_t index = 0; index < v.size(); ++index)
        {
            if (v[index] > max1)
            {
                max2 = max1;
                max1 = v[index];
            }
            else
            {
                max2 = std::max(max2, v[index]);
            }
        }

        std::cout << (long long) max1 * max2 << std::endl;
    }
    return 0;
}


No comments:

Post a Comment