Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main(){
- ios::sync_with_stdio(false);
- int T, N=0, a=0, mark[1001];
- bool flag;
- std::fill(mark, mark+1000, 0);
- vector<int> twos;
- cin>>T;
- if (T < 1 || T > 100) return -1;
- for(register int i = 0; i < T; i++){
- flag = false;
- twos.clear();
- std::fill(mark, mark+1000, 0);
- cin>>N;
- if (N < 1 || N > 1000) continue;
- if (N < 4) {
- cout<<-1<<endl;
- continue;
- }
- for(register int j = 0; j < N; j++){
- cin>>a;
- if (a < 1 || a > 1000){
- flag = true;
- break;
- }
- mark[a]++;
- if (mark[a]==2){
- twos.push_back(a);
- }
- }
- if (flag) continue;
- if (twos.size() == 1||twos.size()==0){
- cout<<-1<<endl;
- }
- else{
- sort(twos.begin(), twos.end(), std::greater<int>());
- cout<<twos[0] * twos[1]<<endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment