天天看點

POJ 3273 Monthly Expense 二分答案

monthly expense

time limit: 2000ms

memory limit: 65536k

total submissions: 13281

accepted: 5362

description

farmer john is an astounding accounting wizard and has realized he might run out of money to run the farm. he has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over

the next n (1 ≤ n ≤ 100,000) days.

fj wants to create a budget for a sequential set of exactly m (1 ≤ m ≤ n) fiscal periods called "fajomonths". each of these fajomonths contains a set of 1 or more consecutive days. every day is contained in exactly one fajomonth.

fj‘s goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.

input

line 1: two space-separated integers: n and m 

lines 2..n+1: line i+1 contains the number of dollars farmer john spends on the ith day

output

line 1: the smallest possible monthly limit farmer john can afford to live with.

sample input

sample output

hint

if farmer john schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. any other method of scheduling gives a larger minimum monthly limit.

又是一個二分題。題目的意思是說,在接下來的n天裡,farmer john每天需要花money[i]錢,把這些天分成k份(每份都是連續的天),要求每份的和盡量少,輸出這個最小的和。

依舊是二分答案二分答案。。。但是特别奇怪,如果用一個res維護目前可行值就會wa,而且r也得用r = mid 而不是r = mid - 1。。。

這個二分真是難