设为首页 加入收藏

TOP

poj 3273(原来以为是dp呢,居然是二分)
2015-07-20 17:57:22 来源: 作者: 【 】 浏览:2
Tags:poj 3273 原来 以为 居然 二分
Monthly Expense
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 14719 Accepted: 5895

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 ≤ MN) 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

7 5
100
400
300
100
500
101
400

Sample Output

500

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.

Source

USACO 2007 March Silver

代码很清楚,相信很容易就懂了。

AC代码:

#include
  
   
using namespace std;
int a[100010];
int main(){
    int n,m;
    int low,high;
    while(cin>>n>>m){
        low=0; high=0;
        for(int i=0;i
   
    >a[i]; high+=a[i]; if(a[i]>low) low=a[i]; } while(low
    
     

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu4921 Map 下一篇ZOJ 2859 二维线段树

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: