using System.Collections.Generic;
public static void Main()
int[] arr = new int[9]{ 5, 6, -5, 5, 3, 5, 3, -2, 0 };
public static void PrintSubArr(int[] arr, int S)
Dictionary<int,List<int>> dict = new Dictionary<int,List<int>>();
dict[sum] = new List<int>(){-1};
for(int i= 0; i< arr.Length-1; i++)
if(!dict.ContainsKey(sum))
dict[sum] = new List<int>(){i};
if(dict.ContainsKey(sum-S))
var tempList = dict[sum-S];
foreach(var startIndex in tempList)
for(int j= startIndex+1; j<=i;j++)
Console.Write(arr[j] + " ");