Minimize the maximum element in constructed Array with sum divisible by K | Java program for the above approach ; Function to find smallest maximum number in an array whose sum is divisible by K . ; Minimum possible sum possible for an array of size N such that its sum is divisible by K ; If sum is not divisible by N ; If sum is divisible by N ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int smallestMaximum ( int N , int K ) { int sum = ( ( N + K - 1 ) / K ) * K ; if ( sum % N != 0 ) return ( sum / N ) + 1 ; else return sum / N ; } public static void main ( String args [ ] ) { int N = 4 ; int K = 3 ; System . out . println ( smallestMaximum ( N , K ) ) ; } }