fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32.  
  33. // ---------- Multi set ----------
  34.  
  35. // Strict Ceil (> x)
  36. int sCeil(multiset<int> &s, int x){
  37.  
  38. auto it = s.upper_bound(x);
  39.  
  40. if(it == s.end()) return -1;
  41.  
  42. return *it;
  43. }
  44.  
  45. // Strict Floor (< x)
  46. int sFloor(multiset<int> &s, int x){
  47.  
  48. auto it = s.lower_bound(x);
  49.  
  50. if(it == s.begin()) return -1;
  51. --it;
  52.  
  53. return *it;
  54. }
  55.  
  56. // Loose Ceil (>= x)
  57. int ceil(multiset<int> &s, int x){
  58.  
  59. auto it = s.lower_bound(x);
  60.  
  61. if(it == s.end()) return -1;
  62.  
  63. return *it;
  64. }
  65.  
  66. // Loose Floor (<= x)
  67. int floor(multiset<int> &s, int x){
  68.  
  69. auto it = s.upper_bound(x);
  70.  
  71. if(it == s.begin()) return -1;
  72. --it;
  73.  
  74. return *it;
  75. }
  76.  
  77.  
  78.  
  79. void solve() {
  80.  
  81. multiset<int> ms = {2, 5, 3, 6, 10, 22, 6, 6, 3};
  82.  
  83. cout << "Multiset => ";
  84. for(auto x : ms) cout << x << " "; cout << endl;
  85.  
  86. int x = 6;
  87.  
  88. // Smallest / Largest
  89. cout << "Smallest(" << x << ") : " << *ms.begin() << endl;
  90. cout << "Largest(" << x << ") : " << *ms.rbegin() << endl;
  91.  
  92. // Strict / Loose
  93. cout << "Strict Ceil (>" << x << ") : " << sCeil(ms, x) << endl;
  94. cout << "Strict Floor (<" << x << ") : " << sFloor(ms, x) << endl;
  95. cout << "Loose Ceil (>=" << x << ") : " << ceil(ms, x) << endl;
  96. cout << "Loose Floor(<=" << x << ") : " << floor(ms, x) << endl;
  97.  
  98. cout << "\n";
  99.  
  100.  
  101.  
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. int32_t main() {
  110. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  111.  
  112. int t = 1;
  113. // cin >> t;
  114. while (t--) {
  115. solve();
  116. }
  117.  
  118. return 0;
  119. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Multiset => 2 3 3 5 6 6 6 10 22 
Smallest(6)       : 2
Largest(6)        : 22
Strict Ceil (>6)  : 10
Strict Floor (<6) : 5
Loose Ceil (>=6)  : 6
Loose Floor(<=6)  : 6

Find(6)           : Found -> 6