Find instances at end of time frame after auto scaling | C ++ program for the above approach ; Function to find the number of instances after compintion ; Traverse the array , arr [ ] ; If current element is less than 25 ; Divide instances by 2 and take ceil value ; If the current element is greater than 60 ; Double the instances ; Print the instances at the end of the traversal ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void finalInstances ( int instances , int arr [ ] , int N ) { int i = 0 ; while ( i < N ) { if ( arr [ i ] < 25 && instances > 1 ) { double temp = ( instances / 2.0 ) ; instances = ( int ) ( ceil ( temp ) ) ; i = i + 10 ; } else if ( arr [ i ] > 60 && instances <= ( 2 * pow ( 10 , 8 ) ) ) { instances = instances * 2 ; i = i + 10 ; } i = i + 1 ; } cout << instances ; } int main ( ) { int instances = 2 ; int arr [ ] = { 25 , 23 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 76 , 80 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; finalInstances ( instances , arr , N ) ; }