Codeforces Round #393 (Div. 2)-D. Travel Card

原题链接

D. Travel Card
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
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

dp[i]表示前i个trip结束后总共需要花多少钱
第i个trip有三种方式计算,三种方式都算一遍使dp[i]达到最小
#include <iostream>
#include <cstdio> 
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#define maxn 100005
#define INF 1000000009
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll num[maxn], dp[maxn];
int main(){
	//freopen("in.txt", "r", stdin); 
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%I64d", num+i);
	}
	dp[0] = 20;
	for(int i = 1; i < n; i++){
		dp[i] = dp[i-1] + 20;
		int l = 0, r = i+1;
		while(l < r){
			int mid = (l + r) >> 1;
			if(num[mid] >= num[i]- 90+1)
			 r = mid;
			else
			 l = mid + 1;
		}
		if(l)
		 dp[i] = min(dp[i], dp[l-1] + 50);
		else
		 dp[i] = min(dp[i], (ll)50);
		l = 0, r = i + 1;
		while(l < r){
			int mid = (l + r) >> 1;
			if(num[mid] >= num[i] - 1440 + 1)
			 r = mid;
			else
			 l = mid + 1; 
		}
		if(l)
		 dp[i] = min(dp[i], dp[l-1] + 120);
		else
		 dp[i] = min(dp[i], (ll)120);
	}
	printf("%I64d\n", dp[0]);
	for(int i = 1; i < n; i++)
	  printf("%I64d\n", dp[i] - dp[i-1]);
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值