$35
Bus Tour
Hangzhou is a beautiful city for tourist. The buses with numbers that begin with 'Y' go to scenic spots, train stations, tourist centers and bus stations (all the things that the tourists need). Y1 is a bus route starting from Lingyin Temple and around the West Lake in the counter clockwise direction. There is N stops for Y1.
The scenery between two adjacent stops can be measured by a integer scale of "niceness". Positive niceness value indicates nice view and negative value indicates the scenery between stops is dull.
Macro Pool is a reporter for Tourists’ World_ who arrived in Hangzhou last week. His task is to find two different stops along the Y1 bur route such that the niceness score is the largest.
Can you help him to find those stops?
Input
The first line of input contains an integer, N, the number of stops along the Y1 bus route, 2 <= N<= 20,000
Each of the next N-1 lines contains a single integer. The i-th integer indicating niceness between stop i and stop i+1.
The absolute value of niceness will not exceed 10^9.
Output If the maximum possible sum between two stops is not positive, your program should print a line:
"Yet another overrated tourist destination"
Otherwise, your program should identify the beginning bus stop i and the ending bus stop j that identify the segment of the route which yields the maximal sum of niceness.
If more than one segment is equally maximally nice, choose the one with the longest bus ride (largest number of stops, j - i). To break ties further in longest maximal segments, choose the segment that begins with the earliest stop (lowest i).
Print a line in the form:
"The nicest part of Y1 is between stops i and j"
Example 1
Example 2
Heating Rod
There is a rod with length L mounted between two fixed walls. When the rod is heated, it will expand lengthwise according to the formula L*(1+T*C) where T is the temperature difference and C is the expansion coefficient of the metal from which the rod is made.
Your task is to calculate the displacement of the center of the rod from its original position.
Input
The input consists of only one line, containing three non-negative numbers: L, T and C, indicating the length of that rod, the temperature heated by and the expanding coefficient. It is guaranteed that the new length after expansion will be no more than 1.5*L.
Output
Print one line, containing a single number D, the displacement of the center of the rod. D should be rounded to 3 decimal places.
Example 1
Example 2
Example 3
Math Homework
Kou just finished her first math class. Her teacher gave her a problem as homework and Kou again, asked you for help.
Recall that prime gap is the difference between two consecutive primes. In this problem you are to find the mode of prime gaps formed by primes in the given lower and upper bound.
Input
The input consists of a single line containing two integers L and U (0 <= L <= U <= 1,000,000), representing the lower and upper bounds.
Output
You should print a single integer representing the mode of prime gaps or -1 if there are multiple single modes or there is no prime gap.
Example 1
Example 2
Example 3
Parcels
Anazon has 6 types of products. Each is packed in a box of height H with base equal to one of the following sizes: 1×1, 2×2, 3×3, 4×4, 5×5, 6×6. (All sizes are specified in feet.)
The individual boxed products are always delivered to customers in the shipping packages with height H and base of 6×6 (again in feet).
To reduce the number of shipping packages (and therefore the cost), Anazon wants you to write a program to calculate the minimal number of packages necessary to deliver the given order of products.
Input A single line containing 6 non-negative integer no greater than 100,000, specifies an order.
The i-th integer indicates the number of boxes of individual size i×i.
Output Output the minimum number of packages needed to ship the order.
E×ample 1
E×ample 2
E×ample 2
Max Sum Subarray
In computer science, the maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum, within a given one-dimensional array A[1…n] of numbers.
Formally, the task is to find indices i and j with 1 <= i <= j <= n, such that the sum a[i] + a[i+1] + … + a[j-1] + a[j] is as large as possible.
For example, for the array of values [−2, 1, −3, 4, −1, 2, 1, −5, 4], the contiguous subarray with the largest sum is [4, −1, 2, 1], with sum 6.
Write a program to calculate such sum with given input array.
Input
The first line contains 1 integer n, the number of elements in the input array. 1 <= n <= 100000.
In the next line, there are n integer indicating the elements of the array. We have -10^9 <= A[i] <= 10^9 for 1 <= i <= n.
Output
Output one line containing the value of the sum for the maximum subarray.
Example 1
Example 2