A family consists of x members. You are given the task to book flight tickets for these
members.
You are given the following information about the airline in which you have to book the tickets:
- : It denotes the cost of one ticket of the flight.
- : It denotes the number of total available seats in the flight.
- : If the numbers of available seats are less than or equal to , then the cost of the flight ticket increases to .
- : It denotes the new hiked cost.
Determine the total cost to book the tickets for all the family members.
Note: The tickets are booked one by one for all the family members.
Example:
Input: p = 6000 , s = 10, t= 5, h = 6500, x= 7
Output: 43000
Approach
C++
#include <bits/stdc++.h>using namespace std;long long totalCost(long long p, long long s,long long t, long long h, long long x){long long cost = 0, cnt = 0;while (s > t){cost += p;s--;cnt++;if (cnt == x)break;}if (cnt < x)cost += (x - cnt) * h;return cost;}int main(){long long p = 6000, s = 10, t = 5, h = 6500, x = 7;cout << totalCost(p, s, t, h, x) << "\n";return 0;}
No comments:
Post a Comment