#K32722. Find Contiguous Subarray with Given Sum

    ID: 24929 Type: Default 1000ms 256MiB

Find Contiguous Subarray with Given Sum

Find Contiguous Subarray with Given Sum

Given an array of n integers and a target sum \( k \), your task is to find any contiguous subarray whose sum equals \( k \). If there are multiple valid subarrays, you may output any one of them.

If no such subarray exists, print -1.

inputFormat

The input is given from standard input (stdin) and consists of three lines:

  • The first line contains an integer \( n \), the number of elements in the array.
  • The second line contains \( n \) space-separated integers representing the array elements.
  • The third line contains an integer \( k \), the target sum.

outputFormat

If there is a contiguous subarray whose sum equals \( k \), output its elements separated by a single space on one line. If no such subarray exists, output -1.

## sample
5
1 2 3 7 5
15
3 7 5

</p>