# Minimize the maximum element in constructed Array with sum divisible by K

Given two integers N and K, the task is to find the smallest value for maximum element of an array of size N consisting of positive integers whose sum of elements is divisible by K.Examples:Input: N = 4, K = 3Output: 2Explanation: Let the array be [2, 2, 1, 1]. Here, sum of elements of this array is divisible by K=3, and maximum element is 2.Input: N = 3, K = 5Output: 2Approach: To find the smallest maximum of an array of size N and having sum divisible by K, try to create an array with the minimum sum possible.The minimum sum of N elements (each having a value greater than 0) that is divisible by K is:

sum = K * ceil(N/K)

Now, if the sum is divisible by N then the maximum element will be sum/N otherwise it is (sum/N + 1).Below is the implementation of above approach.C++ #include using namespace std; 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;} int main(){ int N = 4; int K = 3; cout