Find the final radiations of each Radiated Stations | C # implementation of the approach ; Function to print the final radiations ; Function to create the array of the resultant radiations ; Resultant radiations ; Declaring index counter for left and right radiation ; Effective radiation for left and right case ; Radiation for i - th station ; Radiation increment for left stations ; Radiation increment for right stations ; Print the resultant radiation for each of the stations ; Driver code ; 1 - based indexing
using System ; class GFG { static void print ( int [ ] rStation , int n ) { for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( rStation [ i ] + " ▁ " ) ; Console . WriteLine ( " " ) ; } static void radiated_Station ( int [ ] station , int n ) { int [ ] rStation = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { int li = i - 1 , ri = i + 1 ; int lRad = station [ i ] - 1 , rRad = station [ i ] - 1 ; rStation [ i ] += station [ i ] ; while ( li >= 1 && lRad >= 1 ) { rStation [ li -- ] += lRad -- ; } while ( ri <= n && rRad >= 1 ) { rStation [ ri ++ ] += rRad -- ; } } print ( rStation , n ) ; } public static void Main ( String [ ] args ) { int [ ] station = { 0 , 7 , 9 , 12 , 2 , 5 } ; int n = station . Length - 1 ; radiated_Station ( station , n ) ; } }