Advertisement
Guest User

Untitled

a guest
Aug 21st, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. /*----------------------- Directives -----------------------*/
  2. #include <bits/stdc++.h>
  3.  
  4. /*----------------------- Namespaces -----------------------*/
  5. using namespace std;
  6.  
  7. /*----------------------- Macros -----------------------*/
  8. #define endl '\n'
  9. #define pb push_back
  10. #define pf push_front
  11. #define mem(a,i) memset(a,i,sizeof(a))
  12. #define ff first
  13. #define ss second
  14. #define all(v) v.begin(),v.end()
  15. #define rall(v) v.rbegin(),v.rend()
  16. #define w(t) int t=1,tc=1;cin>>t;while(t--)
  17.  
  18. /*----------------------- Type Definitions -----------------------*/
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21. typedef long double ld;
  22.  
  23. /*----------------------- Maths -----------------------*/
  24. const int MOD = 1000*1000*1000 + 7; // for big mod
  25. template <typename T> inline T gcd(T a, T b){T c;while (b){c = b;b = a % b;a = c;}return a;} // better than __gcd
  26. template <typename T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
  27. template <typename T> inline bool isPrime(T n){for (T i=2;i*i<=n;i++) if(n%i==0) return false; return true;}
  28.  
  29. vector<bool> prime;
  30. template <typename T> vector<T> sieve(T n) {
  31. prime.resize(n+2,true);
  32. prime[0]=false; prime[1]=false; prime[2]=true;
  33.  
  34. vector<T> a;
  35. for (T i=2;i*i<=prime.size();i++) if (prime[i]) for (T j=i*i;j<prime.size();j+=i) prime[j]=false;
  36.  
  37. for (T i=2;i<prime.size();i++) if (prime[i]) a.pb(i);
  38. return a;
  39. }
  40.  
  41. /*----------------------- SOLVE -----------------------*/
  42. void solve() {
  43. int n;
  44. cin>>n;
  45.  
  46.  
  47. vector<int> v(n);
  48. multiset<int> mp;
  49. for (auto &i:v) cin>>i,mp.insert(i);
  50.  
  51. for (int i=0;i<n;i++) {
  52. mp.erase(mp.find(v[i]));
  53. auto it=mp.upper_bound(2*v[i]);
  54.  
  55. if (it==mp.begin()) cout<<-1<<" ";
  56. else cout<<*(--it)<<" ";
  57.  
  58. mp.insert(v[i]);
  59. }
  60. cout<<endl;
  61. }
  62.  
  63. int main() {
  64. ios_base::sync_with_stdio(false);
  65. cin.tie(NULL);
  66.  
  67. // vector<ll> primes = sieve((ll)1e5);
  68.  
  69. w(t) {
  70. cout<<"Case #"<<tc<<": ";
  71. solve();
  72. tc++;
  73. }
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement