Submission

Status:
PPPPPPPPPP

Score: 100

User: YoruoniVamp

Problemset: Consecutive Subsequence

Language: cpp

Time: 0.002 second

Submitted On: 2025-03-13 12:32:33

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned ll
#define cint const int
#define cf const float

cint mxA = 1e6+5, MOD = 1e9+7, INF = 0x3f3f3f3f;
cint d4x[4] = {0, 1, 0, -1}, d4y[4] = {1, 0, -1, 0};
cint d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}, d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

map<int,int> mp;
int mx = INT_MIN, mn = INT_MAX, mxt = INT_MIN, cnt;
string n;
vector<int> ans, tmp;

void solve(){
    while(true){
        cin >> n;
        if(!isdigit(n[n.length()-1])) break;
        if(mp.find(stoi(n)) == mp.end())mp[stoi(n)] = stoi(n)-1;
        mx = max(mx,stoi(n));
        mn = min(mn,stoi(n));
    }for(int i = mx; i >= mn; i--){
        // cout << i << endl;
        while(mp.find(i)!=mp.end()){
            tmp.push_back(i);
            // for(auto j: tmp) cout << j << ' ';
            // cout << endl;
            cnt++;
            i = mp[i];
        }if(mxt<=cnt){
            mxt = cnt;
            ans.clear();
            // for(auto j: tmp) cout << j << ' ';
            // cout << endl;
            for(auto j: tmp) ans.push_back(j);
            // cout << "ANS: ";
            // for(auto j: ans) cout << j << ' ';
            // cout << endl;
        }cnt = 0;
        tmp.clear();
    }for(int i = ans.size()-1; i >= 0; i--) cout << ans[i] << ' ';
    return;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(0);cout.tie(0);
    // freopen("", "r", stdin);
    // freopen("", "w", stdout);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}