Maximize count of planes that can be stopped per second with help of given initial position and speed | C ++ program for the above approach ; Function to find maximum number of planes that can be stopped from landing ; Stores the times needed for landing for each plane ; Iterate over the arrays ; Stores the time needed for landing of current plane ; Update the value of t ; Append the t in set St ; Return the answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxPlanes ( int A [ ] , int B [ ] , int N ) { set < int > St ; for ( int i = 0 ; i < N ; i ++ ) { int t = ( A [ i ] % B [ i ] > 0 ) ? 1 : 0 ; t += ( A [ i ] / B [ i ] ) + t ; St . insert ( t ) ; } return St . size ( ) ; } int main ( ) { int A [ ] = { 1 , 3 , 5 , 4 , 8 } ; int B [ ] = { 1 , 2 , 2 , 1 , 2 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << maxPlanes ( A , B , N ) ; return 0 ; }