Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, v[1001], vf = 0, x;
- int main()
- {
- int st[1001];
- cin >> n;
- for(int i = 1; i <= n; i++){
- cin >> v[i];
- }
- for (int i = 1; i <= n; i++){
- //cout << v[i] << " ";
- if ( vf == 0 )
- {
- st[++vf] = i;
- }
- else
- {
- if ( v[i] <= v[st[vf]] )
- {
- st[++vf] = i;
- }
- else
- {
- //cout << v[st[vf]] <<endl;
- while ( v[i] > v[st[vf]] && vf != 0 )
- {
- //cout << v[st[vf]] <<endl;
- vf--;
- }
- //cout << "----- " << endl;
- st[++vf] = i;
- }
- }
- //cout << st[vf] << endl;
- }
- cout << vf << endl;
- for (int i = 1; i <= vf; i++){
- cout << st[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement