Advertisement
a53

UEMM1

a53
Dec 23rd, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. int main()
  2. {
  3. cin >> n;
  4. for (int i = 1; i <= n; i++)
  5. cin >> a[i];
  6. b[n] = n;
  7. for (int i = n - 1; i; i--)
  8. {
  9. b[i] = i + 1;
  10. while ( a[i] >= a[b[i]] && b[i] < n)
  11. b[i] = b[b[i]];
  12. }
  13. for (int i = 1; i <= n; i++)
  14. if ( b[i] <= i || (b[i] > i && a[b[i]] <= a[i]) )
  15. cout << "-1 ";
  16. else
  17. cout << a[b[i]] << ' ';
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement