Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

Bear has a large, empty ground for him to build a home. He decides to build a row of houses, one after another, say n in total.

The houses are designed with different height. Bear has m workers in total, and the workers must work side by side. So at a time bear can choose some continuous houses, no more than m, and add their heights by one, this takes one day to finish.

Given the designed height for each house, what is the minimum number of days after which all the houses’ heights are no less than the original design?

Input

The first line of input contains a number T, indicating the number of test cases. (T<=50)

For each case, the first line contains two integers n and m: the number of houses and the number of workers. The next line comes with n non-negative numbers, they are the heights of the houses from left to right. (1<=n, m<=100,000, each number will be less than 1,000,000,000)

Output

For each case, output “Case #i: “ first. (i is the number of the test case, from 1 to T). Then output the days when bear’s home can be built.

Sample Input

2
3 3
1 2 3
3 3
3 2 1

Sample Output

Case #1: 3
Case #2: 3

Source

[Submit]   [Go Back]   [Status]

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int sum[110000];
long long int ans=0,d;

int main()
{
    int T,m,n,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        ans=0;  int t;
        scanf("%d%d",&n,&m);
        memset(sum,0,sizeof(sum));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&t);
            if(i-1>=0) sum+=sum[i-1];
            if(t-sum>0)
            {
                d=t-sum;
                sum+=d;
                ans+=d;
                if(i+m<n)
                {
                    sum[i+m]-=d;
                }
            }
        }
        printf("Case #%d: %lld\n",cas++,ans);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

UESTC 1817 Complete Building the Houses的更多相关文章

  1. cdoj 04 Complete Building the Houses 暴力

    Complete Building the Houses Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...

  2. MINIX3 保护模式分析

    3.1 INTEL 保护模式概要 先要说明一个问题:不是 MINIX3 一定要设置这个保护模式,但是在 386 平台上, 引入了这个保护模式机制,MINIX3 不得不设立相关保护模式的内容.由于 38 ...

  3. hdu 3879 Base Station 最大权闭合图

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...

  4. Builder创建者模式

    http://www.codeproject.com/Articles/42415/Builder-Design-Pattern In Elizabeth's day care center, the ...

  5. 原始启动log&新log

    root@Taiyear:/# U-Boot 1.1.3 (Dec 27 2013 - 09:14:28) SoC:MediaTek MT7620 DRAM:  Memory Testing..655 ...

  6. hdu4296 贪心

    E - 贪心 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit I ...

  7. hdu 4296 Buildings(贪婪)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others ...

  8. OpenWrt中对USB文件系统的操作, 以及读写性能测试

    参考 http://h-wrt.com/en/doc/flash 1. 查看usb存储在启动日志中的信息 # dmesg [ 5.720000] usbcore: registered new int ...

  9. LS1021ATWR开发板启动日志分析

    一.背景 LS1021ATWR开发板运行官方的openwrt系统 二.日志分析 2.1 linux相关日志 root@OpenWrt:/# reboot  重启 root@OpenWrt:/# [ 2 ...

随机推荐

  1. iOS:实现图片的无限轮播之使用第三方库SDCycleScrollView

    下载链接:github不断更新地址:https://github.com/gsdios/SDCycleScrollView #import "ViewController.h" # ...

  2. 通过爬虫代理IP快速增加博客阅读量——亲测CSDN有效!

    写在前面 题目所说的并不是目的,主要是为了更详细的了解网站的反爬机制,如果真的想要提高博客的阅读量,优质的内容必不可少. 了解网站的反爬机制 一般网站从以下几个方面反爬虫: 1. 通过Headers反 ...

  3. 二级联动banner【墨芈原创,大神勿喷】

    这个banner效果在几个月前都做了,不过因为代码添乱,而且不宜调用就没发布,经过2周时间间间断断的编写,插件终于搞定了,除框架外其它都开源发布,至于框架没给源码是因为还没做好,后期做好了也会发布出来 ...

  4. 『.Net』微软家的女儿们

    在博客园看到了 一篇文章 <.NET4.0框架退休日期逐渐临近> 写下了这篇文章 —— 记录我和 .Net Framework 的 那些日子. 微软 家有几个 女儿. 2008年,我遇到他 ...

  5. 面试官的七种武器:Java篇

    起源 自己经历过的面试也不少了,互联网的.外企的,都有.总结一下这些面试的经验,发现面试官问的问题其实不外乎几个大类,玩不出太多新鲜玩意的.细细想来,面试官拥有以下七种武器.恰似古龙先生笔下的武侠世界 ...

  6. Java学习笔记(二一)——Java 泛型

    [前面的话] 最近脸好干,掉皮,需要买点化妆品了. Java泛型好好学习一下. [定义] 一.泛型的定义主要有以下两种: 在程序编码中一些包含类型参数的类型,也就是说泛型的参数只可以代表类,不能代表个 ...

  7. jQuery使用之(一)标记元素属性

    jQuery使用主要介绍jQuery如何控制页面,包含元素的属性.css样式风格.DOM模型.表单元素和事件处理等. 标记元素的属性 html中每一个标记都具有一些属性,他们这个标记在页面中呈现各种状 ...

  8. 验证xml是否有效于.dtd文件

    <html> <head> <script language="javascript"> <!-- //加载解析器对象 var xmldo ...

  9. 【转】pageX、clientX、screenX、offsetX、layerX、x

    参考:http://www.cnblogs.com/xesam/archive/2011/12/08/2280509.html chrome: e.pageX——相对整个页面的坐标e.layerX—— ...

  10. Sqlserver 读取EXCEL

    1.1 启用本地读取设置 --启用EXEC sp_configure 'show advanced options', 1RECONFIGUREEXEC sp_configure 'Ad Hoc Di ...