Cheapest Bus Tickets

Problem #427

Tags: interviews puzzle c-1

Who solved this?

No translations... yet

It so happened I'm currently (August 2024) in search for new job - and with interview to position in T-Bank I got quite a heap of small puzzles already. A couple of simpler ones have already found their place at our auxiliary site (String Encoding and Turtle Crawler) - but this one is a bit more advanced (it was said most candidates don't get to it anyway) - so let it live among "puzzles".

Galina, a girl from provincial town, have come to study in a Big University in some Big City. Campus is large, a number of majestic old buildings along the street - and sometimes she needs to travel between them quickly, so she rides a bus. Being practical, she wonders about the way to minimize ticket cost. But it is not an easy matter for there are several types of tickets:

So we are given an array of numbers, representing how many times Galina should travel each day in the upcoming month. So there are 28 to 31 values, all of them comparatively small. We want to know lowest possible cost of tickets for the month.

Input: the first line gives D - number of days in the month.
Next line contains corresponding amount of small integers - rides on every day.

Answer: should give a single value - minimum possible cost of tickets.

Example:

input:
30
2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 3 4

answer:
51

P.S. to be honest, when I completed the code, we both with interviewer were pretty confused by the logic, so I still am not sure my own solution is correct, even though it produces seemingly good results on few basic test-cases we have checked.

You need to login to get test data and submit solution.