-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsecutive Subsequence.cpp
More file actions
49 lines (47 loc) · 901 Bytes
/
Consecutive Subsequence.cpp
File metadata and controls
49 lines (47 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "iostream"
#include "vector"
#include "algorithm"
#include "queue"
#include "set"
#include "unordered_set"
#include "stack"
#include "map"
#include "limits.h"
#include "cstdio"
#include "math.h"
#include <numeric>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> arr(n);
for (int &i : arr) { std::cin >> i; }
map<int,int> dp;
int ans = 0;
int lst = 0;
for(int i = 0; i<n; i++)
{
int x = arr[i];
dp[x]=dp[x-1]+1;
if(ans<dp[x])
{
ans = dp[x];
lst = x;
}
}
vector<int> res;
for(int i = n-1; i>=0; i--)
{
if(arr[i]==lst)
{
res.push_back(i);
lst--;
}
}
reverse(res.begin(),res.end());
cout<<ans<<endl;
for(auto x:res)
cout<<x+1<<" ";
}