CF Educational Codeforces Round 15
A. Maximum Increase
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input
The first line contains single positive integer n () — the number of integers.
The second line contains n positive integers , , …, ().
OutPut
Print the maximum length of an increasing subarray of the given array.
Examples
input
5
1 7 2 11 15
output
3
input
6
100 100 100 100 100 100
output
1
input
3
1 2 3
output
3
题解
题意大致是最大的连续上升连续子序列长度
简单判断一下连续的子序列长度,然后求一个max就可以了
//author: CHC |
B. Powers of Two
You are given n integers , , …, . Find the number of pairs of indexes i, j (i < j) that is a power of 2 (i. e. some integer x exists so that ).
Input
The first line contains the single positive integer n () — the number of integers.
The second line contains n positive integers , , …, ().
Output
Print the number of pairs of indexes i, j (i < j) that + is a power of 2.
Examples
input
4
7 3 2 1
output
2
input
3
1 1 1
output
3
题解
题意大致为给一个数列,求这个数列中两数和为2的次方的对数个数。
因为其数列的值范围都在,不会超过,因此对于第i个数,求在之间,有多少个j满足的结果为2的次方
我们首先将数列排序,然后依次枚举判断,加上即可
//author: CHC |
C. Cellular Network
You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.
Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.
If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.
Input
The first line contains two positive integers n and m () — the number of cities and the number of cellular towers.
The second line contains a sequence of n integers a1, a2, …, an () — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.
The third line contains a sequence of m integers b1, b2, …, bm () — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.
Output
Print minimal r so that each city will be covered by cellular network.
Examples
input
3 2
-2 2 4
-3 0
output
4
input
5 3
1 5 10 14 17
4 11 15
output
3
题解
题目大意为在一条直线上,有n个城市和m个能量塔,每个能量塔可以保护距离在r之内的城市,然后给出n个城市的x坐标和m个能量塔的x坐标,然后求能够覆盖所有城市的最小的r
因为其范围比较大,并且,r
是单调的,若r可以覆盖所有的城市的话,那么r+1
一定可以覆盖所有的城市,因此我们可以确定一个区间(最大r
和最小l
的区间),然后在这个区间内,确定一个点mid
,判断r=mid
时能否覆盖所有的城市
判断的方法非常重要,问题转化为求 给定一个r
,n个城市和m个能量塔,这m个能量塔能否覆盖完所有的城市
我们可以枚举这n个城市,然后判断这n个城市在r
的范围内有没有能量塔,若在r
的范围内没有能量塔,那么就一定不行,若所有的城市在r
范围内都有能量塔,那么一定可行
//author: CHC |
D. Road to Post Office
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.
Vasiliy’s car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.
To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b).
Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.
Input
The first line contains 5 positive integers d, k, a, b, t (; ; a < b), where:
d — the distance from home to the post office;
k — the distance, which car is able to drive before breaking;
a — the time, which Vasiliy spends to drive 1 kilometer on his car;
b — the time, which Vasiliy spends to walk 1 kilometer on foot;
t — the time, which Vasiliy spends to repair his car.
Output
Print the minimal time after which Vasiliy will be able to reach the post office.
Examples
input
5 2 1 4 10
output
14
input
5 2 1 4 5
output
13
题解
题目大意为Vas想去d
公里以外的邮局,然后它有一辆车,但这辆车有问题,它每走k
公里就必须要修t
秒才能继续走
车每走1公里需要话费a
秒时间,它也可以走路,走路每走1公里需要b
秒的时间
问它到达邮局最少的时间,车在起点的时候是好的
; ; a < b
一开始一定用车走k
公里,然后走了k
公里之后,需要判断在(d-k)/k*k
的路程里,车走比较划算还是人走比较划算,然后再判断最后的(d-k)%k
这段路人走还是车走,然后就可以计算出了
//author: CHC |