15502022-11-23 18:15:081478Síkság (55)cpp11Elfogadva 55/5552ms8332 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    // ifstream cin("be.txt");
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    multiset<pair<int, int>> s;
    int p1 = 1, p2 = 1;
    s.insert({a[p1], p1});
    int ans = 0, ansi;
    while (p1 <= n && p2 <= n)
    {
        while (p2 < n && s.empty() ||
               prev(s.end())->first - s.begin()->first <= 1)
        {
            p2++;
            s.insert({a[p2], p2});
        }
        int akt = p2 - p1;
        if (akt > ans)
        {
            ans = akt;
            ansi = p1;
        }
        s.erase({a[p1], p1});
        p1++;
    }
    cout << ans << " " << ansi << ln;

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1808 KiB
2Elfogadva0/06ms2504 KiB
3Elfogadva2/22ms2260 KiB
4Elfogadva2/22ms2784 KiB
5Elfogadva2/22ms2580 KiB
6Elfogadva2/22ms2808 KiB
7Elfogadva3/32ms2796 KiB
8Elfogadva2/23ms3032 KiB
9Elfogadva3/33ms3104 KiB
10Elfogadva3/37ms3536 KiB
11Elfogadva3/36ms3608 KiB
12Elfogadva3/36ms4780 KiB
13Elfogadva3/343ms4544 KiB
14Elfogadva3/343ms8332 KiB
15Elfogadva3/346ms6924 KiB
16Elfogadva3/350ms5232 KiB
17Elfogadva3/352ms7096 KiB
18Elfogadva3/350ms6528 KiB
19Elfogadva3/352ms7172 KiB
20Elfogadva3/352ms6728 KiB
21Elfogadva3/325ms5628 KiB
22Elfogadva3/343ms7148 KiB