text: Check if a line at 45 degree can divide the plane into two equal weight parts |  ; Checking if a plane can be divide by a line at 45 degrees such that weight sum is equal ; Rotating each point by 45 degrees and calculating prefix sum . Also , finding maximum and minimum x coordinates ; storing weight sum upto x - y point ; Finding prefix sum ; Line passes through i , so it neither falls left nor right . ; Driven code
code: using System ; using System . Collections . Generic ; public class GFG { static void is_partition_possible ( int n , int [ ] x , int [ ] y , int [ ] w ) { Dictionary < int , int > weight_at_x = new Dictionary < int , int > ( ) ; int max_x = ( int ) - 2e3 , min_x = ( int ) 2e3 ; for ( int i = 0 ; i < n ; i ++ ) { int new_x = x [ i ] - y [ i ] ; max_x = Math . Max ( max_x , new_x ) ; min_x = Math . Min ( min_x , new_x ) ; if ( weight_at_x . ContainsKey ( new_x ) ) { weight_at_x [ new_x ] += w [ i ] ; } else { weight_at_x . Add ( new_x , w [ i ] ) ; } } List < int > sum_till = new List < int > ( ) ; sum_till . Add ( 0 ) ; for ( int s = min_x ; s <= max_x ; s ++ ) { if ( ! weight_at_x . ContainsKey ( s ) ) { sum_till . Add ( sum_till [ sum_till . Count - 1 ] ) ; } else { sum_till . Add ( sum_till [ sum_till . Count - 1 ] + weight_at_x [ s ] ) ; } } int total_sum = sum_till [ sum_till . Count - 1 ] ; int partition_possible = 0 ; for ( int i = 1 ; i < sum_till . Count ; i ++ ) { if ( sum_till [ i ] == total_sum - sum_till [ i ] ) partition_possible = 1 ; if ( sum_till [ i - 1 ] == total_sum - sum_till [ i ] ) partition_possible = 1 ; } Console . WriteLine ( partition_possible == 1 ? " YES " : " NO " ) ; } static public void Main ( ) { int n = 3 ; int [ ] x = { - 1 , - 2 , 1 } ; int [ ] y = { 1 , 1 , - 1 } ; int [ ] w = { 3 , 1 , 4 } ; is_partition_possible ( n , x , y , w ) ; } }