Napoleon chose a city for Advertising his company's product. There are S streets in that city. Each day he travels one street. There are N buildings in a street that are located at points
. Each building has some height(Say meters). Napoleon stands at the point . His height is . Now Napoleon starts communicating with the people of each building. He can communicate with people of a particular building only if he can see that building. If he succeeds to communicate with any particular building then his boss gives him . i.e. if he communicates with buildings in a day, then he will earn . Now Napoleon wants to know his maximum earnings for each day.
Note: All the points are on a Straight Line and Napoleon is always standing at point 0.
Example:
Input: n = 6, r = 3, height = [8, 2, 3, 11, 11, 10]
Output: 6
Approach
C++
#include <bits/stdc++.h>using namespace std;long long maximizeEarning(long long n, long long r,long long height[]){long long max1 = height[0];long long res = 1;for (long long i = 1; i < n; i++){if (height[i] > max1)res++;max1 = max(max1, height[i]);}return res * r;}int main(){long long n = 6, r = 3;long long height[n] = {8, 2, 3, 11, 11, 10};cout << maximizeEarning(n, r, height) << "\n";return 0;}
No comments:
Post a Comment