Submission

Status:

-P-PP-PPPP

Subtask/Task Score:

70/100

Score: 70

User: theem1502

Problemset: Consecutive Subsequence

Language: cpp

Time: 0.003 second

Submitted On: 2026-02-24 22:39:51

#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<int> thearray;
    int count = 0;
    while(true) {
        string a;
        cin >> a;

        if (a[0] == '-' && a.length() > 1) {
              int num = a.length();
        int thenum = pow(10, num-2);
        int val = 0;
        for (int i = 1; i < num; i++) {
            val += (a[i] - '0') * thenum;
            thenum /=10;
        }
        thearray.push_back(-1*val);
        count++;
        continue;

        }

        if ((a[0] >= 'a' && a[0] <= 'z') || (a[0] >= 'A' && a[0] <= 'Z')) {
            break;
        }


        int num = a.length();
        int thenum = pow(10, num-1);
        int val = 0;
        for (int i = 0; i < num; i++) {
            val += (a[i] - '0') * thenum;
            thenum /=10;
        }
        thearray.push_back(val);
        count++;

    }
    /*
    for (int i = 0; i < count; i++) {
        cout << thearray[i] << " ";
    }
*/
    sort(thearray.begin(), thearray.end());
    /*
    cout << "\n\n\n\n";
       for (int i = 0; i < count; i++) {
        cout << thearray[i] << " ";
    }
    */
    int maxseq;
    vector<int> seq;
    vector<int> maxseqarray;
    seq.push_back(thearray[0]);
    maxseqarray.push_back(thearray[0]);
    int currseq = 1;
    maxseq = 1;
    for (int i = 1; i < count; i++) {
    //    cout << "hi";
        if (thearray[i] == thearray[i-1] + 1 || thearray[i] == thearray[i-1]) {
            seq.push_back(thearray[i]);
            currseq++;
            if (currseq > maxseq) {
                maxseq = currseq;
                maxseqarray.clear();
                for (auto x: seq) {
                    maxseqarray.push_back(x);

                }

            }
        }
        else {
             currseq = 1;
             seq.clear();
             seq.push_back(thearray[i]);

        }

    }

    int theval = unique(maxseqarray.begin(), maxseqarray.end()) - maxseqarray.begin();


 //  cout << "hello";
    for (int i = 0; i < theval; i++) {
        cout << maxseqarray[i] << " ";

    }

}