首页 > 其他 > 详细

Codeforces Round #393 (Div. 2) D题Travel Card(map,dp)解题报告

时间:2017-02-13 00:05:41      阅读:232      评论:0      收藏:0      [点我收藏+]

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 ti (0?≤?ti?≤?109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti?+?1?>?ti holds for all 1?≤?i?<?n.

Output

Output n integers. For each trip, print the sum the passenger is charged after it.

Example

Input
3
10
20
30
Output
20
20
10
Input
10
13
45
46
60
103
115
126
150
256
516
Output
20
20
10
0
20
0
0
20
20
10

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.

用map写的dp。建立花多少钱时的日期的记录,以此为dp对象。

参考代码:

 1 #include<bits/stdc++.h>
 2 #include <iostream>
 3 #include <queue>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <algorithm>
 7 using namespace std;
 8 typedef long long ll;
 9 typedef unsigned long long ull;
10 map<int,int> re;
11 int n;
12 int range=-1;
13 int tem;
14 int he=0;
15 int oh;
16 int an;
17 int main()
18 {
19     scanf("%d",&n);
20 //    re[0]=0;
21     while(n--)
22     {
23         an=0;
24         scanf("%d",&tem);
25         if(tem<=range)
26         {
27             printf("0\n");
28             continue;
29         }
30         else
31         {
32             oh=he-40;
33             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+89>=tem)
34             {
35                 range=max(range,re[oh]+89);
36                 an=10;
37             }
38             oh=he-110;
39             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+1439>=tem)
40             {
41                 range=max(range,re[oh]+1439);
42                 an=10;
43             }
44             if(an!=0)
45             {
46                 re[he]=tem;
47                 he+=10;
48                 printf("%d\n",an);
49                 continue;
50             }
51             oh=he-30;
52             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+89>=tem)
53             {
54                 range=max(range,re[oh]+89);
55             }
56             oh=he-100;
57             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+1439>=tem)
58             {
59                 range=max(range,re[oh]+1439);
60             }
61             range=max(range,tem);
62             printf("20\n");
63             re[he]=tem;
64             he+=20;
65         }
66     }
67 }

 

Codeforces Round #393 (Div. 2) D题Travel Card(map,dp)解题报告

原文:http://www.cnblogs.com/quintessence/p/6392049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!