Codechef•Sep 06, 2025
Car Trip
Hazrat Ali
Codechef
Usually, the cost of the car is Rs 10 per km. However, since Chef has booked the car for the whole day, he needs to pay for at least 300 kms even if the car runs less than 300 kms.
If the car ran X kms, determine the cost Chef needs to pay.
Input Format
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single integer X - denoting the number of kms Chef travelled.
Output Format
For each test case, output the cost Chef needs to pay.
Constraints
- 1≤T≤100
- 1≤X≤1000
Sample 1:
Input
5 800 3 299 301 300
Output
8000 3000 3000 3010 3000
Solution
#include <iostream>
using namespace std;
int cost(int x) {
if (x <= 300) {
return 3000;
} else {
return x * 10;
}
}
int main() {
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
cout << cost(x) << endl;
}
return 0;
}