78692024-01-11 14:21:42szasztundeSíkság (55)cpp17Accepted 55/5552ms8432 KiB
#include <iostream>
#include <set>

using namespace std;

int a[100001];

int main(){
    int n,x;
    cin>>n;
    for(int i=1; i<=n; i++) cin >> a[i];
    int i=1,j=1,maxim=0,index=0;
    multiset<int> h;
    h.insert(a[1]);
    while (i<=n && j<=n){
        int kezd=*h.begin(),veg=*h.rbegin();
        while (veg-kezd<=1){
            j++;
            h.insert(a[j]);
            kezd=*h.begin(); veg=*h.rbegin();
        }
        if (h.size()-1>maxim){
            maxim=h.size()-1; index=i;
        }
        /*cout<<"i="<<i<<" a[i]="<<a[i]<<" Torles elott ";
        multiset<int>::iterator it;
        for (it = h.begin(); it != h.end(); ++it) {
            cout << *it << " ";
        }
        cout <<"Torles utan ";*/
        h.erase(h.find(a[i]));
        //multiset<int>::iterator it;
        /*for (it = h.begin(); it != h.end(); ++it) {
            cout << *it << " ";
        }
        cout << endl;*/
        i++;
    }
    cout<<maxim<< " "<<index;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1816 KiB
2Accepted0/06ms2508 KiB
3Accepted2/23ms2268 KiB
4Accepted2/23ms2428 KiB
5Accepted2/23ms2668 KiB
6Accepted2/23ms2860 KiB
7Accepted3/33ms3092 KiB
8Accepted2/23ms3180 KiB
9Accepted3/33ms3296 KiB
10Accepted3/37ms3712 KiB
11Accepted3/36ms3948 KiB
12Accepted3/36ms4924 KiB
13Accepted3/341ms4688 KiB
14Accepted3/343ms8432 KiB
15Accepted3/346ms7108 KiB
16Accepted3/348ms5316 KiB
17Accepted3/352ms7384 KiB
18Accepted3/348ms6712 KiB
19Accepted3/352ms7164 KiB
20Accepted3/350ms6916 KiB
21Accepted3/325ms5804 KiB
22Accepted3/343ms7304 KiB