POJ 3273, Monthly Expense

Time Limit: 2000MS  Memory Limit: 65536K
Total Submissions: 4105  Accepted: 1620


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
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


//  POJ3273.cpp : Defines the entry point for the console application.
//

#include 
< iostream >
#include 
< numeric >
#include 
< algorithm >
using   namespace  std;

int  main( int  argc,  char *  argv[])
{
    
int  N, M;
    
int  day[ 100005 ];

    scanf(
" %d %d " & N,  & M);
    
for ( int  i  =   0 ; i  <  N;  ++ i)
        scanf(
" %d " & day[i]);

    
int  maxv  =  accumulate( & day[ 0 ], & day[N], 0 );

    
int  minv  =   * max_element( & day[ 0 ], & day[N]);

    
int  midv;

    
while (minv  <  maxv)
    {
        midv 
=  (minv  +  maxv) >> 1 ;
        
int  k  =   0 ;
        
int  sum  =   0 ;
        
for  ( int  i  =   0 ; i  <  N;  ++ i)
        {
            sum 
+=  day[i];
            
if  (sum  >  midv)
            {
                sum 
=  day[i];
                
++ k;
            }
        }

        
if  (k  <  M) maxv  =  midv;
        
else  minv  =  midv  +   1 ;
    }

    cout 
<<  maxv  <<  endl;
    
return   0 ;
}

转载于:https://www.cnblogs.com/asuran/archive/2009/10/28/1591017.html

资源下载链接为: https://pan.quark.cn/s/4d91f8fa210b Docker CE(社区版)是 Docker 公司推出的开源容器运行时平台,能让开发者将应用及其依赖打包成可移植的容器,进而发布到各类流行的 Linux 系统或 Windows 系统上,还具备虚拟化功能。本教程着重介绍在 CentOS 7.x 系统离线安装 Docker CE 20.10.12 版本的详细过程,涵盖其全部依赖包。在 CentOS 7 中,Docker CE 的作用在于提供轻量级虚拟化技术,让应用程序在名为容器的隔离环境中运行,相较于传统虚拟机,由于共享宿主机操作系统,其在资源占用和启动时间上更具优势。 离线安装 Docker CE 20.10.12 的操作步骤如下: 准备离线安装包:先在有网络的环境下,将 Docker CE 20.10.12 的 RPM 包以及其所有依赖(如 docker-ce、docker-ce-cli、containerd.io 等)下载好,确保不遗漏任何必要文件,然后把它们打包成一个压缩文件,比如命名为 “docker-ce-20.10.12”。 上传到服务器:借助 FTP、SCP 等文件传输工具,把包含 RPM 包的压缩文件传输到 CentOS 7 服务器上。 解压并安装:在服务器上定位到压缩包所在位置,依据压缩文件格式,若为 .zip,执行 unzip docker-ce-20.10.12.zip;若为 .tar.gz,则运行 tar -zxvf docker-ce-20.10.12.tar.gz 来解压。 安装依赖:在解压后的当前目录下,运行 yum install *.rpm 命令,以此安装所有 .rpm 文件,涵盖 Docker CE 及其必需依赖。需注意,CentOS 7 要通过 EPEL 仓库获取部分依赖,若系统未配置 EPEL,可
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值