D. Travel Card

Codeforces
IDCF760D
Time2000ms
Memory256MB
Difficulty
binary searchdptwo pointers
English · Original
Chinese · Translation
Formal · Original
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a ticket for one trip costs 20 byteland rubles, 2. a ticket for 90 minutes costs 50 byteland rubles, 3. a ticket for one day (1440 minutes) costs 120 byteland rubles. Note that a ticket for _x_ minutes activated at time _t_ can be used for trips started in time range from _t_ to _t_ + _x_ - 1, inclusive. Assume that all trips take exactly one minute. To simplify the choice for the passenger, the system automatically chooses the optimal tickets. After each trip starts, the system analyses all the previous trips and the current trip and chooses a set of tickets for these trips with a minimum total cost. Let the minimum total cost of tickets to cover all trips from the first to the current is _a_, and the total sum charged before is _b_. Then the system charges the passenger the sum _a_ - _b_. You have to write a program that, for given trips made by a passenger, calculates the sum the passenger is charged after each trip. ## Input The first line of input contains integer number _n_ (1 ≤ _n_ ≤ 105) — the number of trips made by passenger. Each of the following _n_ lines contains the time of trip _t__i_ (0 ≤ _t__i_ ≤ 109), measured in minutes from the time of starting the system. All _t__i_ are different, given in ascending order, i. e. _t__i_ + 1 > _t__i_ holds for all 1 ≤ _i_ < _n_. ## Output Output _n_ integers. For each trip, print the sum the passenger is charged after it. [samples] ## Note In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had already paid 40 rubles, so it is necessary to charge 10 rubles only.
Bytesburg 引入了一种新型的公共交通票务系统。现在所有交通工具都使用一张通用的交通卡。乘客每次乘车时刷一下卡片,系统将根据票价进行扣费。 票价结构如下:共有三种票种: 请注意,一个在时间 #cf_span[t] 激活的 #cf_span[x] 分钟票,可用于在时间范围 [#cf_span[t], #cf_span[t + x - 1]] 内(含端点)开始的乘车。假设所有乘车均恰好耗时一分钟。 为简化乘客的选择,系统会自动选择最优的票务组合。每次乘车开始后,系统会分析所有之前的乘车记录和当前这次乘车,并为这些乘车选择一组总成本最小的票。设覆盖从第一次到当前这次所有乘车所需的最小总费用为 #cf_span[a],而乘客此前已支付的总金额为 #cf_span[b],则系统将向乘客收取 #cf_span[a - b] 的金额。 你需要编写一个程序,根据乘客的乘车记录,计算每次乘车后乘客被收取的金额。 输入的第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 10^5])——乘客的乘车次数。 接下来的 #cf_span[n] 行,每行包含一次乘车的时间 #cf_span[ti](#cf_span[0 ≤ ti ≤ 10^9]),单位为从系统启动开始经过的分钟数。所有 #cf_span[ti] 互不相同,且按升序给出,即对所有 #cf_span[1 ≤ i < n] 都有 #cf_span[ti + 1 > ti]。 输出 #cf_span[n] 个整数。对每次乘车,输出乘车后乘客被收取的金额。 在第一个例子中,系统的工作方式如下:对于第一次和第二次乘车,购买两张单次票更便宜,因此每次扣费 #cf_span[20] 卢布;第三次乘车后,系统发现购买一张 #cf_span[90] 分钟的票更划算。这张票售价 #cf_span[50] 卢布,而乘客此前已支付 #cf_span[40] 卢布,因此只需再扣费 #cf_span[10] 卢布。 ## Input 输入的第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 10^5])——乘客的乘车次数。接下来的 #cf_span[n] 行,每行包含一次乘车的时间 #cf_span[ti](#cf_span[0 ≤ ti ≤ 10^9]),单位为从系统启动开始经过的分钟数。所有 #cf_span[ti] 互不相同,且按升序给出,即对所有 #cf_span[1 ≤ i < n] 都有 #cf_span[ti + 1 > ti]。 ## Output 输出 #cf_span[n] 个整数。对每次乘车,输出乘车后乘客被收取的金额。 [samples] ## Note 在第一个例子中,系统的工作方式如下:对于第一次和第二次乘车,购买两张单次票更便宜,因此每次扣费 #cf_span[20] 卢布;第三次乘车后,系统发现购买一张 #cf_span[90] 分钟的票更划算。这张票售价 #cf_span[50] 卢布,而乘客此前已支付 #cf_span[40] 卢布,因此只需再扣费 #cf_span[10] 卢布。
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of trips. Let $ T = (t_1, t_2, \dots, t_n) $ be a strictly increasing sequence of trip times, where $ 0 \le t_1 < t_2 < \dots < t_n \le 10^9 $. Let the ticket types be: - Type 1: Costs $ c_1 $, valid for 1 trip. - Type 2: Costs $ c_2 $, valid for 90 minutes. - Type 3: Costs $ c_3 $, valid for 1440 minutes. For a trip at time $ t $, a ticket activated at time $ a $ covers all trips in $ [a, a + d - 1] $, where $ d $ is the validity duration. Let $ A_k $ be the minimum total cost to cover the first $ k $ trips. Let $ \Delta_k = A_k - A_{k-1} $ be the charge after the $ k $-th trip, with $ A_0 = 0 $. **Constraints** 1. $ 1 \le n \le 10^5 $ 2. $ 0 \le t_i \le 10^9 $, $ t_{i+1} > t_i $ for all $ i \in \{1, \dots, n-1\} $ 3. $ c_1, c_2, c_3 \in \mathbb{R}^+ $ (fixed constants, not input explicitly but implied by context) **Objective** For each $ k \in \{1, \dots, n\} $, compute: $$ \Delta_k = A_k - A_{k-1}, \quad \text{where} \quad A_k = \min_{\substack{j \in \{k\} \\ \text{or } j < k}} \left\{ \begin{array}{l} A_{k-1} + c_1, \\ \min_{\substack{j : t_k - t_j < 90}} \{ A_{j-1} + c_2 \}, \\ \min_{\substack{j : t_k - t_j < 1440}} \{ A_{j-1} + c_3 \} \end{array} \right\} $$ with $ A_0 = 0 $. Output $ \Delta_1, \Delta_2, \dots, \Delta_n $.
Samples
Input #1
3
10
20
30
Output #1
20
20
10
Input #2
10
13
45
46
60
103
115
126
150
256
516
Output #2
20
20
10
0
20
0
0
20
20
10
API Response (JSON)
{
  "problem": {
    "name": "D. Travel Card",
    "description": {
      "content": "A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF760D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Bytesburg 引入了一种新型的公共交通票务系统。现在所有交通工具都使用一张通用的交通卡。乘客每次乘车时刷一下卡片,系统将根据票价进行扣费。\n\n票价结构如下:共有三种票种:\n\n请注意,一个在时间 #cf_span[t] 激活的 #cf_span[x] 分钟票,可用于在时间范围 [#cf_span[t], #cf_span[t + x - 1]] 内(含端点)开始的乘车。假设所有乘车均恰好耗时一...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of trips.  \nLet $ T = (t_1, t_2, \\dots, t_n) $ be a strictly increasing sequence of trip times, where $ 0 \\le t_1 < t_2 < \\dots < t_n \\le 10^...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments