fork download
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t; cin>>t;
  8. while(t>0)
  9. {
  10. int n; cin>>n;
  11. int a=0,b=0,s=INT_MAX,p;
  12. for(int i=0;i<n;i++)
  13. {
  14. cin>>p;
  15. if(p==1)a=1;
  16. if((p!=1 && p%2!=0)||p==2)
  17. {
  18. b=p;
  19. if(b<s)
  20. s=b;
  21. }
  22. }
  23. if(a==1)
  24. cout<<s<<"\n";
  25. else
  26. cout<<-1<<"\n";
  27. t--;
  28. }
  29. }
Success #stdin #stdout 0s 4340KB
stdin
2
3
1 2 3
4
5 5 5 2
stdout
2
-1