codeparrot/xlcost-text-to-code huggingface dataset:
Maximize sum of remaining elements after every removal of the array half with greater sum | C # program to implement the above approach ; Function to find the maximum sum ; Base Case ; Check if ( mapped key is found in the dictionary ; Traverse the array ; Store left prefix sum ; Store right prefix sum ; Compare the left and right values ; Store the value in dp array ; Return the readonly answer ; Function to print maximum sum ; Stores prefix sum ; Store results of subproblems ; Traversing the array ; Add prefix sum of array ; Print the answer ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int [ , ] dp = new int [ 100 , 100 ] ; static int maxweight ( int s , int e , Dictionary < int , int > pre ) { if ( s == e ) return 0 ; if ( dp [ s , e ] != - 1 ) return dp [ s , e ] ; int ans = 0 ; for ( int i = s ; i < e ; i ++ ) { int left = pre [ i ] - pre [ s - 1 ] ; int right = pre [ e ] - pre [ i ] ; if ( left < right ) ans = Math . Max ( ans , ( int ) ( left + maxweight ( s , i , pre ) ) ) ; if ( left == right ) ans = Math . Max ( ans , Math . Max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; if ( left > right ) ans = Math . Max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; dp [ s , e ] = ans ; } return dp [ s , e ] ; } static void maxSum ( int [ ] arr , int n ) { Dictionary < int , int > pre = new Dictionary < int , int > ( ) ; pre . Add ( - 1 , 0 ) ; pre . Add ( 0 , arr [ 0 ] ) ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) dp [ i , j ] = - 1 ; } for ( int i = 1 ; i < n ; i ++ ) pre . Add ( i , pre [ i - 1 ] + arr [ i ] ) ; Console . Write ( ( maxweight ( 0 , n - 1 , pre ) ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 6 , 2 , 3 , 4 , 5 , 5 } ; maxSum ( arr , 6 ) ; } }
Find K smallest leaf nodes from a given Binary Tree | C # program of the above approach ; Structure of binary tree node ; Function to create new node ; Utility function which calculates smallest three nodes of all leaf nodes ; Check if current root is a leaf node ; Traverse the left and right subtree ; Function to find the K smallest nodes of the Binary Tree ; Sorting the Leaf nodes array ; Loop to print the K smallest Leaf nodes of the array ; Driver Code ; Construct binary tree ; Function call
using System ; using System . Collections . Generic ; class GFG { class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static List < int > storeLeaf ( Node root , List < int > arr ) { if ( root == null ) return arr ; if ( root . left == null && root . right == null ) { arr . Add ( root . data ) ; return arr ; } arr = storeLeaf ( root . left , arr ) ; arr = storeLeaf ( root . right , arr ) ; return arr ; } static void KSmallest ( Node root , int k ) { List < int > arr = new List < int > ( ) ; arr = storeLeaf ( root , arr ) ; arr . Sort ( ) ; for ( int i = 0 ; i < k ; i ++ ) { if ( i < arr . Count ) { Console . Write ( arr [ i ] + " ▁ " ) ; } else { break ; } } } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . left . left = newNode ( 21 ) ; root . left . right = newNode ( 5 ) ; root . left . right . right = newNode ( 8 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 19 ) ; KSmallest ( root , 3 ) ; } }
Check if all the pairs of an array are coprime with each other | C # implementation of the above approach ; Function to check if all the pairs of the array are coprime with each other or not ; Check if GCD of the pair is not equal to 1 ; All pairs are non - coprime Return false ; Function return gcd of two number ; Driver Code
using System ; class GFG { static bool allCoprime ( int [ ] A , int n ) { bool all_coprime = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( gcd ( A [ i ] , A [ j ] ) != 1 ) { all_coprime = false ; break ; } } } return all_coprime ; } static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 3 , 5 , 11 , 7 , 19 } ; int arr_size = A . Length ; if ( allCoprime ( A , arr_size ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Smallest power of 2 consisting of N digits | C # program of the above approach ; Function to return smallest power of 2 consisting of N digits ; calculate log2 N indirectly using log ( ) method ; Driver Code
using System ; class GFG { static int smallestNum ( int n ) { double power = log2 ( 10 ) ; return ( int ) Math . Ceiling ( ( n - 1 ) * power ) ; } static double log2 ( int N ) { return ( Math . Log ( N ) / Math . Log ( 2 ) ) ; } public static void Main ( ) { int n = 4 ; Console . Write ( smallestNum ( n ) ) ; } }
Find a valid parenthesis sequence of length K from a given valid parenthesis sequence | C # program for the above approach ; Function to find the subsequence of length K forming valid sequence ; Stores the resultant String ; Check whether character at index i is visited or not ; Traverse the String ; Push index of open bracket ; Pop and mark visited ; Increment count by 2 ; Append the characters and create the resultant String ; Return the resultant String ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static String findString ( String s , int k ) { int n = s . Length ; String ans = " ▁ " ; Stack < int > st = new Stack < int > ( ) ; bool [ ] vis = new bool [ n ] ; List < bool > vis ( n , false ) ; int count = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( s [ i ] == ' ( ' ) { st . Push ( i ) ; } if ( count < k && s [ i ] == ' ) ' ) { vis [ st . Peek ( ) ] = true ; st . Pop ( ) ; vis [ i ] = true ; count += 2 ; } } for ( int i = 0 ; i < n ; ++ i ) { if ( vis [ i ] == true ) { ans += s [ i ] ; } } return ans ; } public static void Main ( String [ ] args ) { String s = " ( ) ( ) ( ) " ; int K = 2 ; Console . Write ( findString ( s , K ) ) ; } }
Node having maximum number of nodes less than its value in its subtree | C # program for the above approach ; Stores the nodes to be deleted ; Structure of a Tree node ; Function to create a new node ; Function to compare the current node key with keys received from it left & right tree by Post Order traversal ; Base Case ; Find nodes lesser than the current root in the left subtree ; Find nodes lesser than the current root in the right subtree ; Stores all the nodes less than the current node 's ; Add the nodes which are less than current node in [ ] left ; Add the nodes which are less than current node in [ ] right ; Create a combined vector for pass to it 's parent ; Stores key that has maximum nodes ; Return the vector of nodes ; Driver Code ; Given Tree ; Function call ; Print the node value
using System ; using System . Collections . Generic ; class GFG { static Dictionary < int , Boolean > mp = new Dictionary < int , Boolean > ( ) ; static int max_v , rootIndex ; class Node { public int key ; public Node left , right ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return ( temp ) ; } static List < int > findNodes ( Node root ) { if ( root == null ) { return new List < int > ( ) ; } List < int > left = findNodes ( root . left ) ; List < int > right = findNodes ( root . right ) ; List < int > combined = new List < int > ( ) ; int count = 0 ; for ( int i = 0 ; i < left . Count ; i ++ ) { if ( left [ i ] < root . key ) { count += 1 ; } combined . Add ( left [ i ] ) ; } for ( int i = 0 ; i < right . Count ; i ++ ) { if ( right [ i ] < root . key ) { count += 1 ; } combined . Add ( right [ i ] ) ; } combined . Add ( root . key ) ; if ( count > max_v ) { rootIndex = root . key ; max_v = count ; } return combined ; } public static void Main ( String [ ] args ) { Node root = newNode ( 3 ) ; root . left = newNode ( 4 ) ; root . right = newNode ( 6 ) ; root . right . left = newNode ( 4 ) ; root . right . right = newNode ( 5 ) ; root . left . left = newNode ( 10 ) ; root . left . right = newNode ( 2 ) ; max_v = 0 ; rootIndex = - 1 ; findNodes ( root ) ; Console . Write ( rootIndex ) ; } }
Maximum sum path in a matrix from top | C # program for the above approach ; Function to find the maximum sum path in the grid ; Dimensions of grid [ , ] ; Stores maximum sum at each cell sum [ i , j ] from cell sum [ 0 , 0 ] ; Iterate to compute the maximum sum path in the grid ; Update the maximum path sum ; Return the maximum sum ; Driver Code
using System ; class GFG { static int MaximumPath ( int [ , ] grid ) { int N = grid . GetLength ( 0 ) ; int M = grid . GetLength ( 1 ) ; int [ , ] sum = new int [ N + 1 , M + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= M ; j ++ ) { sum [ i , j ] = Math . Max ( sum [ i - 1 , j ] , sum [ i , j - 1 ] ) + grid [ i - 1 , j - 1 ] ; } } return sum [ N , M ] ; } public static void Main ( String [ ] args ) { int [ , ] grid = { { 1 , 2 } , { 3 , 5 } } ; Console . Write ( MaximumPath ( grid ) ) ; } }
Maximize cost of deletions to obtain string having no pair of similar adjacent characters | C # program for the above approach ; Function to find maximum cost to remove consecutive characters ; Maximum cost ; Traverse from 0 to len ( s ) - 2 ; If characters are identical ; Add cost [ i ] if its maximum ; Add cost [ i + 1 ] if its maximum ; Increment i ; Return the final max count ; Driver code ; Given string s ; Given cost of removal ; Function call
using System ; using System . Collections . Generic ; class GFG { static int Maxcost ( string s , int [ ] cost ) { int maxcost = 0 ; int i = 0 ; while ( i < s . Length - 1 ) { if ( s [ i ] == s [ i + 1 ] ) { if ( cost [ i ] > cost [ i + 1 ] ) maxcost += cost [ i ] ; else { maxcost += cost [ i + 1 ] ; cost [ i + 1 ] = cost [ i ] ; } } i ++ ; } return maxcost ; } public static void Main ( string [ ] args ) { string s = " abaac " ; int [ ] cost = { 1 , 2 , 3 , 4 , 5 } ; Console . Write ( Maxcost ( s , cost ) ) ; } }
Maximum count of values of S modulo M lying in a range [ L , R ] after performing given operations on the array | C # program for the above approach ; Lookup table ; Function to count the value of S after adding arr [ i ] or arr [ i - 1 ] to the sum S at each time ; Base Case ; Store the mod value ; If the mod value lies in the range then return 1 ; Else return 0 ; Store the current state ; If already computed , return the computed value ; Recursively adding the elements to the sum adding ai value ; Adding arr [ i ] - 1 value ; Return the maximum count to check for root value as well ; Avoid counting idx = 0 as possible solution we are using idx != 0 ; Return the value of current state ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static Dictionary < Tuple < int , int > , int > dp = new Dictionary < Tuple < int , int > , int > ( ) ; static int countMagicNumbers ( int idx , int sum , int [ ] a , int n , int m , int l , int r ) { if ( idx == n ) { int Temp = sum % m ; if ( Temp == l || Temp == r || ( Temp > l && Temp < r ) ) return dp [ new Tuple < int , int > ( idx , sum ) ] = 1 ; else return dp [ new Tuple < int , int > ( idx , sum ) ] = 0 ; } Tuple < int , int > curr = new Tuple < int , int > ( idx , sum ) ; if ( dp . ContainsKey ( curr ) ) return dp [ curr ] ; int ls = countMagicNumbers ( idx + 1 , sum + a [ idx ] , a , n , m , l , r ) ; int rs = countMagicNumbers ( idx + 1 , sum + ( a [ idx ] - 1 ) , a , n , m , l , r ) ; int temp1 = Math . Max ( ls , rs ) ; int temp = sum % m ; if ( ( temp == l || temp == r || ( temp > l && temp < r ) ) && idx != 0 ) { temp1 += 1 ; } return dp [ new Tuple < int , int > ( idx , sum ) ] = temp1 ; } static void Main ( ) { int N = 5 , M = 22 , L = 14 , R = 16 ; int [ ] arr = { 17 , 11 , 10 , 8 , 15 } ; Console . Write ( countMagicNumbers ( 0 , 0 , arr , N , M , L , R ) ) ; } }
Check if a path exists for a cell valued 1 to reach the bottom right corner of a Matrix before any cell valued 2 | C # program for the above approach ; Function to check if cell with value 1 doesn 't reaches the bottom right cell or not ; Initialise the deque ; Traverse the matrix ; Push 1 to front of queue ; Push 2 to back of queue ; Store all the possible direction of the current cell ; Run multi - source BFS ; Get the front element ; Pop the front element ; If 1 reached corner first ; Insert new point in queue ; If 1 can 't reach the bottom  right then return false ; Driver Code ; Given matrix ; Function call
using System ; using System . Collections . Generic ; class GFG { static bool reachesBottom ( int [ , ] a , int n , int m ) { Queue < int [ ] > q = new Queue < int [ ] > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( a [ i , j ] == 1 ) { q . Enqueue ( new int [ ] { i , j , 1 } ) ; } else if ( a [ i , j ] == 2 ) { q . Enqueue ( new int [ ] { i , j , 2 } ) ; } a [ i , j ] = 0 ; } } int [ ] dx = { - 1 , 0 , 1 , 0 } ; int [ ] dy = { 0 , 1 , 0 , - 1 } ; while ( q . Count != 0 ) { int [ ] front = q . Peek ( ) ; q . Dequeue ( ) ; int i = front [ 0 ] , j = front [ 1 ] ; int t = front [ 2 ] ; if ( a [ i , j ] == 1 ) continue ; a [ i , j ] = 1 ; if ( t == 1 && ( i == n - 1 && j == m - 1 ) ) { return true ; } for ( int d = 0 ; d < 4 ; d ++ ) { int ni = i + dx [ d ] ; int nj = j + dy [ d ] ; if ( ni >= 0 && ni < n && nj >= 0 && nj < m ) { q . Enqueue ( new int [ ] { ni , nj , t } ) ; } } } return false ; } public static void Main ( String [ ] args ) { int [ , ] matrix = { { 0 , 2 , 0 } , { 0 , 1 , 0 } , { 0 , 2 , 0 } } ; if ( reachesBottom ( matrix , 3 , 3 ) ) { Console . Write ( " YES " ) ; } else { Console . Write ( " NO " ) ; } } }
Smallest element from all square submatrices of size K from a given Matrix | C # program for the above approach ; Function to returns a smallest elements of all KxK submatrices of a given NxM matrix ; Stores the dimensions of the given matrix ; Stores the required smallest elements ; Update the smallest elements row - wise ; Update the minimum column - wise ; Store the readonly submatrix with required minimum values ; Return the resultant matrix ; Function call ; Print resultant matrix with the minimum values of KxK sub - matrix ; Driver Code ; Given matrix ; Given K
using System ; class GFG { public static int [ , ] matrixMinimum ( int [ , ] nums , int K ) { int N = nums . GetLength ( 0 ) ; int M = nums . GetLength ( 1 ) ; int [ , ] res = new int [ N - K + 1 , M - K + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M - K + 1 ; j ++ ) { int min = int . MaxValue ; for ( int k = j ; k < j + K ; k ++ ) { min = Math . Min ( min , nums [ i , k ] ) ; } nums [ i , j ] = min ; } } for ( int j = 0 ; j < M ; j ++ ) { for ( int i = 0 ; i < N - K + 1 ; i ++ ) { int min = int . MaxValue ; for ( int k = i ; k < i + K ; k ++ ) { min = Math . Min ( min , nums [ k , j ] ) ; } nums [ i , j ] = min ; } } for ( int i = 0 ; i < N - K + 1 ; i ++ ) for ( int j = 0 ; j < M - K + 1 ; j ++ ) res [ i , j ] = nums [ i , j ] ; return res ; } public static void smallestinKsubmatrices ( int [ , ] arr , int K ) { int [ , ] res = matrixMinimum ( arr , K ) ; for ( int i = 0 ; i < res . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < res . GetLength ( 1 ) ; j ++ ) { Console . Write ( res [ i , j ] + " ▁ " ) ; } Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { int [ , ] arr = { { - 1 , 5 , 4 , 1 , - 3 } , { 4 , 3 , 1 , 1 , 6 } , { 2 , - 2 , 5 , 3 , 1 } , { 8 , 5 , 1 , 9 , - 4 } , { 12 , 3 , 5 , 8 , 1 } } ; int K = 3 ; smallestinKsubmatrices ( arr , K ) ; } }
Queries to find Kth greatest character in a range [ L , R ] from a string with updates | C # program to implement the above approach ; Function to find the kth greatest character from the string ; Sorting the String in non - increasing Order ; Function to print the K - th character from the subString S [ l ] . . S [ r ] ; 0 - based indexing ; SubString of str from the indices l to r . ; Extract kth Largest character ; Function to replace character at pos of str by the character s ; Index of S to be updated . ; char to be replaced at index in S ; Driver Code ; Given String ; Queries
using System ; class GFG { static char find_kth_largest ( char [ ] str , int k ) { Array . Sort ( str ) ; reverse ( str ) ; return str [ k - 1 ] ; } static char [ ] reverse ( char [ ] a ) { int i , n = a . Length ; char t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } static char printchar ( String str , int l , int r , int k ) { l = l - 1 ; r = r - 1 ; String temp = str . Substring ( l , r - l + 1 ) ; char ans = find_kth_largest ( temp . ToCharArray ( ) , k ) ; return ans ; } static void updateString ( char [ ] str , int pos , char s ) { int index = pos - 1 ; char c = s ; str [ index ] = c ; } public static void Main ( String [ ] args ) { String str = " abcddef " ; Console . Write ( printchar ( str , 1 , 2 , 2 ) + " STRNEWLINE " ) ; updateString ( str . ToCharArray ( ) , 4 , ' g ' ) ; Console . Write ( printchar ( str , 1 , 5 , 4 ) + " STRNEWLINE " ) ; } }
Split array into two subarrays such that difference of their sum is minimum | C # Program for above approach ; Function to return minimum difference between sum of two subarrays ; To store total sum of array ; Calculate the total sum of the array ; Stores the prefix sum ; Stores the minimum difference ; Traverse the given array ; To store minimum difference ; Update minDiff ; Return minDiff ; Driver Code ; Given array ; Length of the array
using System ; class GFG { static int minDiffSubArray ( int [ ] arr , int n ) { int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) total_sum += arr [ i ] ; int prefix_sum = 0 ; int minDiff = int . MaxValue ; for ( int i = 0 ; i < n - 1 ; i ++ ) { prefix_sum += arr [ i ] ; int diff = Math . Abs ( ( total_sum - prefix_sum ) - prefix_sum ) ; if ( diff < minDiff ) minDiff = diff ; } return minDiff ; } public static void Main ( String [ ] args ) { int [ ] arr = { 7 , 9 , 5 , 10 } ; int n = arr . Length ; Console . WriteLine ( minDiffSubArray ( arr , n ) ) ; } }
Maximize count of non | C # program to implement the above approach ; Function to count the maximum number of subarrays with sum K ; Stores all the distinct prefixSums obtained ; Stores the prefix sum of the current subarray ; Stores the count of subarrays with sum K ; If a subarray with sum K is already found ; Increase count ; Reset prefix sum ; Clear the set ; Insert the prefix sum ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int CtSubarr ( int [ ] arr , int N , int K ) { HashSet < int > st = new HashSet < int > ( ) ; int prefixSum = 0 ; st . Add ( prefixSum ) ; int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { prefixSum += arr [ i ] ; if ( st . Contains ( prefixSum - K ) ) { res += 1 ; prefixSum = 0 ; st . Clear ( ) ; st . Add ( 0 ) ; } st . Add ( prefixSum ) ; } return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { - 2 , 6 , 6 , 3 , 5 , 4 , 1 , 2 , 8 } ; int N = arr . Length ; int K = 10 ; Console . WriteLine ( CtSubarr ( arr , N , K ) ) ; } }
Count of subarrays consisting of only prime numbers | C # Program to implement the above approach ; Function to check if a number is prime or not . ; If n has any factor other than 1 , then n is non - prime . ; Function to return the count of subarrays made up of prime numbers only ; Stores the answer ; Stores the count of continuous prime numbers in an array ; If the current array element is prime ; Increase the count ; Update count of subarrays ; If the array ended with a continuous prime sequence ; Driver Code
using System ; class GFG { static bool is_prime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static int count_prime_subarrays ( int [ ] ar , int n ) { int ans = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( is_prime ( ar [ i ] ) ) count ++ ; else { if ( count != 0 ) { ans += count * ( count + 1 ) / 2 ; count = 0 ; } } } if ( count != 0 ) ans += count * ( count + 1 ) / 2 ; return ans ; } public static void Main ( String [ ] args ) { int N = 10 ; int [ ] ar = { 2 , 3 , 5 , 6 , 7 , 11 , 3 , 5 , 9 , 3 } ; Console . Write ( count_prime_subarrays ( ar , N ) ) ; } }
Minimum Subarray flips required to convert all elements of a Binary Array to K | C # program to implement the above approach ; Function to count the minimum number of subarray flips required ; Iterate the array ; If arr [ i ] and flag are equal ; Return the answer ; Driver code
using System ; class GFG { static int minSteps ( int [ ] arr , int n , int k ) { int i , cnt = 0 ; int flag ; if ( k == 1 ) flag = 0 ; else flag = 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == flag ) { cnt ++ ; flag = ( flag + 1 ) % 2 ; } } return cnt ; } public static void Main ( ) { int [ ] arr = { 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 } ; int n = arr . Length ; int k = 1 ; Console . Write ( minSteps ( arr , n , k ) ) ; } }
Minimize Sum of an Array by at most K reductions | C # program to implement the above approach ; Function to obtain the minimum possible sum from the array by K reductions ; Implements the MaxHeap ; Insert elements into the MaxHeap ; Insert maximum / 2 ; Stores the sum of remaining elements ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int minSum ( int [ ] a , int n , int k ) { List < int > q = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { q . Add ( a [ i ] ) ; } q . Sort ( ) ; while ( q . Count != 0 && k > 0 ) { int top = q [ q . Count - 1 ] / 2 ; q [ q . Count - 1 ] = top ; k -- ; q . Sort ( ) ; } int sum = 0 ; while ( q . Count != 0 ) { sum += q [ 0 ] ; q . RemoveAt ( 0 ) ; } return sum ; } static public void Main ( ) { int n = 4 ; int k = 3 ; int [ ] a = { 20 , 7 , 5 , 4 } ; Console . WriteLine ( minSum ( a , n , k ) ) ; } }