现在的位置: 首页 > 综合 > 正文

poj 2519

2013年10月25日 ⁄ 综合 ⁄ 共 2742字 ⁄ 字号 评论关闭

Cutting Necklace
Time Limit: 20000MS   Memory Limit: 65536K
Total Submissions: 1217   Accepted: 150

Description

Today is Valentine's Day. Gnaf Ynot is going to present a beautiful necklace to his girl friend Mxxjx. He has bought a necklace of pearls some time ago. The necklace consists of many sheeny pearls and is very pretty. However, the necklace is too long for his girl friend. So Gnaf Ynot has to cut a slice from the necklace so that he can get a shorter one. He wants that the cut slice of necklace can be as evenly bright as possible, i.e. the average brightness of the slice should be maximized. Gnaf Ynot requests your help. 

The necklace is in the form of a ring of pearls. Each pearl has a brightness. Your task is to cut a substring of pearls from the ring, so that the substring has the largest average brightness of pearls. The substring you cut should not be too long or too short as well. To help Gnaf Ynot making Mxxjx happy, please try your best to solve this problem!

Input

Input contains multiple test cases. Each test case starts a line containing three numbers N, L, U (1 <= L <= U <= N <= 1000000), which are the number of pearls of the necklace, the permitted shortest length and the longest length of the cut slice. Then the following line gives the brightness of each pearl (the value of brightness are integers and in the range of [-1000, 1000]).

Output

For each test case print the largest average brightness of the slice you cut from the necklace in one line. The result should be represented using fraction form such as A/B (here A and B are integers, B > 0 and (A, B) = 1).

Sample Input

4 2 3 4 -1 3 1 4 2 2 4 -1 3 1

Sample Output

8/3 5/2

Source

 

分析:引用某牛

假设答案为X那么一定存在一段数a[ i ] a[ i+1 ] ...a[ j ]/ j-i+1 的值=X

那么就是说a[ i ]+a[ i+1 ]+...a[ j ] = ( j-i+1 )*X

          ( a[ i ]-X )+( a[ i+1 ]-X )+...( a[ j ]-X ) = 0 且X要尽量大 , 那么我们可以2分X取一个使得等式>=0且最大的X。。这道题就转换成一个判定一个环中最大的子串和是否>=0,这可以用队列来实现。。。


 

抱歉!评论已关闭.