188522025-11-07 11:10:40ubormaciLegmesszebbi rossz sorrendű (35 pont)cpp17Elfogadva 35/35114ms16652 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

std::lcm(ll a, ll b), std::gcd(int a, int b)

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

void solve() {

	ll n;
	cin >> n;
	set<ll> s;
	map<ll,vector<ll>> mp;
	for(ll i = 1; i <= n; i++) {
		s.insert(i);
		ll h;
		cin >> h;
		mp[h].push_back(i);
	}

	ll mx = -1;
	ll a = -1, b = -1;
	for(const auto & [num, v] : mp) {

		// a set-ben olyan indexek vannak, amelyek elemei nagyobbak a mostaninal

		for(const auto & x : v) {
			s.erase(x);
		}

		for(const auto & x : v) {

			if(s.empty()) {
				continue;
			}

			ll find = *s.begin();

			if(find > x) {
				continue;
			}

			ll len = x - find;
			if(len > mx) {
				mx = len;
				a = find;
				b = x;
			}

		}
	}

	if(mx == -1) {
		cout << "-1";
	}else{
		cout << a << " " << b;
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base35/35
1Elfogadva0/01ms316 KiB
2Elfogadva0/0108ms12784 KiB
3Elfogadva1/11ms316 KiB
4Elfogadva1/11ms508 KiB
5Elfogadva1/11ms316 KiB
6Elfogadva1/11ms316 KiB
7Elfogadva1/11ms316 KiB
8Elfogadva1/12ms564 KiB
9Elfogadva1/12ms732 KiB
10Elfogadva1/13ms824 KiB
11Elfogadva1/14ms1000 KiB
12Elfogadva2/230ms5172 KiB
13Elfogadva2/237ms5940 KiB
14Elfogadva2/237ms6376 KiB
15Elfogadva2/224ms4148 KiB
16Elfogadva2/241ms6564 KiB
17Elfogadva2/272ms9012 KiB
18Elfogadva2/286ms10404 KiB
19Elfogadva2/2104ms11444 KiB
20Elfogadva2/2104ms11572 KiB
21Elfogadva2/2114ms12824 KiB
22Elfogadva2/2108ms12852 KiB
23Elfogadva2/2105ms16436 KiB
24Elfogadva2/297ms16652 KiB