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. NetBios网络基础及编程

    开始学习(算是复习)网络编程了,第一个就是局域网的netbios协议编程. 首先了解一下什么是netbios:IBM公司为PC-Network开发的一套网络标准.,NetBIOS最广泛的应用之一就是对 ...

  2. Bootstrap系列 -- 28. 下拉菜单状态

    下拉菜单项的默认的状态(不用设置)有悬浮状态(:hover)和焦点状态(:focus). 下拉菜单项除了上面两种状态,还有当前状态(.active)和禁用状态(.disabled).这两种状态使用方法 ...

  3. 教你用netstat-实践案例

    netstat命令的功能是显示网络连接.路由表和网络接口信息,可以让用户得知目前都有哪些网络连接正在运作. 该命令的一般格式为: netstat [选项] 命令中各选项的含义如下: -a 显示所有so ...

  4. [BZOJ 3143][HNOI2013]游走(数学期望)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋 ...

  5. 【BZOJ1011】【HNOI2008】遥远的行星(乱搞)

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1444  Solved ...

  6. [poj1742]coin

    题意:多重背包的w=v特殊情况 分析:此题如果用单调队列O(nv)会被无耻卡常数…… 然后鉴于此题W=V,所以只存在背包恰好为i的是否存在,即bool型的f[i]是否为1 即往背包染色上面考虑 如果是 ...

  7. jQuery基础之(二)jQuery中的$

    在jQuery中,最常用的莫过于使用美元符号$,它提供了各种各样的丰富功能.包括选择页面中一个或者一类元素.作为功能函数的前缀.windows.onload的完善,创建DOM节点等.本文介绍jQuer ...

  8. 输入年月,输出月份有几天(分别用了if——else和switch)

    首先是switch做的 class Program { static void Main(string[] args) {/* 题目要求:请用户输入年份,输入月份,输出该月的天数. 思路:一年中月份的 ...

  9. Lucene 4.7 --创建索引

    Lucene的最新版本和以前的语法或者类名,类规定都相差甚远 0.准备工作: 1). Lucene官方API http://lucene.apache.org/core/4_7_0/index.htm ...

  10. hasSet,TreeSet,ArrayList,LinkedList,Vector,HashMap,HashTable,TreeMap利用Iterator进行输出

    基础类,没有重写hashCode()和equals()方法: package niukewang; import java.util.Objects; public class setClass { ...