Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "MONITOR"
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- int n, p[N];
- ll a[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- cin >> a[p[i] = i];
- }
- void Solve()
- {
- sort(p + 1, p + n + 1, [&](const int &x, const int &y)
- { return a[x] < a[y] || (a[x] == a[y] && x < y); });
- pair<int, int> ans = {-1, 0};
- for (int i = 1, j = 1; i <= n; ++i)
- {
- while (j <= n && a[p[i]] == a[p[j]])
- ++j;
- ans = max(ans, make_pair(p[j - 1] - p[i], -p[i]));
- i = j - 1;
- }
- cout << a[-ans.second] << "\n"
- << ans.first + 1;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement