Vous êtes sur la page 1sur 4

Billboards(20 points) ADZEN is a very popular advertising firm in your city.

In every road you can see their advertising billboards. Recently they are facing a serious challenge , MG Road the most used and beautiful road in your city has been almost filled by the billboards and this is having a negative effect on the natural view. On people's demand ADZEN has decided to remove some of the billboards in such a way that there are no more than K billboards standing together in any part of the road. You may assume the MG Road to be a straight line with N billboards.Initially there is no gap between any two adjecent billboards. ADZEN's primary income comes from these billboards so the billboard removing process has to be done in such a way that the billboards remaining at end should give maximum possible profit among all possible final configurations.Total profit of a configuration is the sum of the profit values of all billboards present in that configuration. Given N,K and the profit value of each of the N billboards, output the maximum profit that can be obtained from the remaining billboards under the conditions given. Input description Ist line contain two space seperated integers N and K. Then follow N lines , each line contains the profit value of a billboard in order 1 to N. Sample Input 62 1 2 3 4 5 6 Sample Output 16 Explanation In given input there are 6 billboards and after the process no more than 2 should be together.

So remove 1st and 4th billboards giving a configuration _ 2 3_ 5 6 having a profit of 16. No other configuration has a profit more than 16.So the answer is 16. Constraints 1 <= N <= 1,00,000(10^5) 1 <= K <= N 0 <= profit value of any billboard <= 2,000,000,000(2*10^9)

Connect the country (20 Points) We have a country containing N cities. Each day we choose 2 cities such that there is no road between them and build a road between them. We choose each pair of nonadjacent cities with equal probability. Let X be the number of days before we obtain a connected country. What is the expected value of X? Output the integer part of answer. Input format: First line of input as an integer N. N <= 30 Output format: Print an integer being the result of the test. Sample Testcases: Input #00: 3 Output #00: 2 Input #01: 4 Output #01: 3

In the first example, first two roads are sufficient for connecting the cities so the answer would be 2. In the second example if the first three roads of the country are edges of a triangle, then we need a fourth road to make the country connected, otherwise the country would be connected with first three roads. The probability of the former situation is 4/20 (number of triple of roads that make a triangle divided by number of ways we can choose 3 different roads), and the probability of former situation is 16/20. So the result would be 4/20*4 + 16/20*3 = 3.2 and since you have to print only the integer part as output, print 3

A number is called lucky if the sum of its digits, as well as the sum of the squares of its digits is a prime number. How many numbers between A and B are lucky? Input: The first line contains the number of test cases T. Each of the next T lines contains two integers, A and B. Output: Output T lines, one for each case containing the required answer for the corresponding case. Constraints: 1 <= T <= 10000 1 <= A <= B <= 10^18 Sample Input: 2 1 20 120 130

Sample Output: 4 1 Explanation: For the first case, the lucky numbers are 11, 12, 14, 16. For the second case, the only lucky number is 120.

Vous aimerez peut-être aussi