Check if all K | C # program to implement the above approach ; Function reverses the elements of the array ; Function to check all subset - sums of K - length subsets in [ ] A is greater that that in the array [ ] B or not ; Sort the array in ascending order ; Sort the array in descending order ; Stores sum of first K elements of [ ] A ; Stores sum of first K elements of [ ] B ; Traverse both the arrays ; Update sum1 ; Update sum2 ; If sum1 exceeds sum2 ; Driver Code
using System ; public class GFG { static void reverse ( int [ ] myArray ) { Array . Sort ( myArray ) ; Array . Reverse ( myArray ) ; } static bool checkSubsetSum ( int [ ] A , int [ ] B , int N , int K ) { Array . Sort ( A ) ; Array . Sort ( B ) ; reverse ( B ) ; int sum1 = 0 ; int sum2 = 0 ; for ( int i = 0 ; i < K ; i ++ ) { sum1 += A [ i ] ; sum2 += B [ i ] ; } if ( sum1 > sum2 ) { return true ; } return false ; } public static void Main ( String [ ] args ) { int [ ] A = { 12 , 11 , 10 , 13 } ; int [ ] B = { 7 , 10 , 6 , 2 } ; int N = A . Length ; int K = 3 ; if ( checkSubsetSum ( A , B , N , K ) ) { Console . Write ( " YES " ) ; } else { Console . Write ( " NO " ) ; } } }