SHARE
TWEET

Untitled

a guest Jun 26th, 2016 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     ios::sync_with_stdio(false);
  9.     int T, N=0, a=0, mark[1001];
  10.     bool flag;
  11.     std::fill(mark, mark+1000, 0);
  12.     vector<int> twos;
  13.     cin>>T;
  14.     if (T < 1 || T > 100) return -1;
  15.     for(register int i = 0; i < T; i++){
  16.         flag = false;
  17.         twos.clear();
  18.         std::fill(mark, mark+1000, 0);
  19.         cin>>N;
  20.         if (N < 1 || N > 1000) continue;
  21.         if (N < 4) {
  22.             cout<<-1<<endl;
  23.             continue;
  24.         }
  25.         for(register int j = 0; j < N; j++){
  26.             cin>>a;
  27.             if (a < 1 || a > 1000){
  28.                 flag = true;
  29.                 break;
  30.             }
  31.             mark[a]++;
  32.             if (mark[a]==2){
  33.                 twos.push_back(a);
  34.             }
  35.         }
  36.         if (flag) continue;
  37.         if (twos.size() == 1||twos.size()==0){
  38.             cout<<-1<<endl;
  39.         }
  40.         else{
  41.             sort(twos.begin(), twos.end(), std::greater<int>());
  42.             cout<<twos[0] * twos[1]<<endl;
  43.         }
  44.     }
  45.     return 0;
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top