Advertisement
sherry_ahmos

give me this pizza

Feb 26th, 2023
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <set>
  7. #include <algorithm>
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. #define ll long long
  13. #define cy cout << "YES\n"
  14. #define cn cout << "NO\n"
  15. #define nl "\n"
  16. #define fi first
  17. #define se second
  18. #define MOD 1000000007
  19. #define inf 2000000000
  20. #define PI acos(-1)
  21. #define all(v) v.begin(), v.end()
  22. constexpr ll LINF = 1LL << 62;
  23. #define sz(s) s.size()
  24. #define f0r(j, n) for (ll i = j; i < n; i++)
  25. #define cin_2d(vec, n, m)                               \
  26.     for (int i = 0; i < n; i++)                         \
  27.         for (int j = 0; j < m && cin >> vec[i][j]; j++) \
  28.             ;
  29. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0)
  30.  
  31. template <typename T = int>
  32. istream &operator>>(istream &in, vector<T> &v)
  33. {
  34.     for (auto &x : v)
  35.         in >> x;
  36.     return in;
  37. }
  38.  
  39. template <typename T = int>
  40. ostream &operator<<(ostream &out, const vector<T> &v)
  41. {
  42.     for (const T &x : v)
  43.         out << x << " ";
  44.     return out;
  45. }
  46.  
  47. void sherry()
  48. {
  49.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  50. #ifndef ONLINE_JUDGE
  51.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  52. #endif
  53. }
  54.  
  55. void solve()
  56. {
  57.     int n;
  58.     cin >> n;
  59.     vector<int> v(n), fre(55, -1), ans(n);
  60.     cin >> v;
  61.     for (int i = n - 1; i >= 0; i--)
  62.     {
  63.         fre[v[i]] = i;
  64.         int num = n + 1;
  65.         for (int j = v[i] + 1; j <= 50; j++)
  66.         {
  67.             if (fre[j] != -1)
  68.             {
  69.                 num = min(num, fre[j]);
  70.             }
  71.         }
  72.         ans[i] = ((num == n + 1) ? -1 : v[num]);
  73.     }
  74.     cout << ans;
  75. }
  76. int main()
  77. {
  78.     sherry();
  79.     int t = 1;
  80.     // cin >> t;
  81.     while (t--)
  82.     {
  83.         solve();
  84.     }
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement