Advertisement
Dang_Quan_10_Tin

MONITOR TS10 PTNK 2020-2021

Jan 5th, 2022 (edited)
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #define task "MONITOR"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. constexpr int N = 1e5 + 5;
  13. int n, p[N];
  14. ll a[N];
  15.  
  16. void Read()
  17. {
  18.     cin >> n;
  19.  
  20.     for (int i = 1; i <= n; ++i)
  21.         cin >> a[p[i] = i];
  22. }
  23.  
  24. void Solve()
  25. {
  26.     sort(p + 1, p + n + 1, [&](const int &x, const int &y)
  27.          { return a[x] < a[y] || (a[x] == a[y] && x < y); });
  28.  
  29.     pair<int, int> ans = {-1, 0};
  30.  
  31.     for (int i = 1, j = 1; i <= n; ++i)
  32.     {
  33.         while (j <= n && a[p[i]] == a[p[j]])
  34.             ++j;
  35.  
  36.         ans = max(ans, make_pair(p[j - 1] - p[i], -p[i]));
  37.  
  38.         i = j - 1;
  39.     }
  40.  
  41.     cout << a[-ans.second] << "\n"
  42.          << ans.first + 1;
  43. }
  44.  
  45. int32_t main()
  46. {
  47.     ios::sync_with_stdio(0);
  48.     cin.tie(0);
  49.     cout.tie(0);
  50.     if (fopen(task ".INP", "r"))
  51.     {
  52.         freopen(task ".INP", "r", stdin);
  53.         freopen(task ".OUT", "w", stdout);
  54.     }
  55.  
  56.     Read();
  57.     Solve();
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement