Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- b[n] = n;
- for (int i = n - 1; i; i--)
- {
- b[i] = i + 1;
- while ( a[i] >= a[b[i]] && b[i] < n)
- b[i] = b[b[i]];
- }
- for (int i = 1; i <= n; i++)
- if ( b[i] <= i || (b[i] > i && a[b[i]] <= a[i]) )
- cout << "-1 ";
- else
- cout << a[b[i]] << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement