fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. const int MOD = 1000000007;
  5.  
  6. void init_code() {
  7. #ifndef ONLINE_JUDGE
  8. freopen("input.txt", "r", stdin);
  9. freopen("output.txt", "w", stdout);
  10. #endif
  11. }
  12.  
  13. int32_t main() {
  14. //init_code();
  15. int t;
  16. cin >> t;
  17. while (t--) {
  18. int n;
  19. cin>>n;
  20. vector<int> a(n);
  21. for(int i=0;i<n;i++) {
  22. cin>>a[i];
  23. }
  24. int l=0;
  25. int r=n-1;
  26. int target=n-2;
  27. sort(a.begin(),a.end());
  28. while(l<=r) {
  29. if(a[l]*a[r]==target) {
  30. cout<<a[l]<<" "<<a[r]<<"\n";
  31. break;
  32. } else if(a[l]*a[r]<target) {
  33. l++;
  34. } else {
  35. r--;
  36. }
  37. }
  38. //cout<<1<<" "<<n-2<<"\n";
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 5284KB
stdin
5
3
1 1 2
11
3 3 4 5 6 7 8 9 9 10 11
8
8 4 8 3 8 2 8 1
6
2 1 4 5 3 3
8
1 2 6 3 8 5 5 3
stdout
1 1
3 3
2 3
1 4
1 6