博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
foj2013
阅读量:5782 次
发布时间:2019-06-18

本文共 1302 字,大约阅读时间需要 4 分钟。

ContractedBlock.gif
ExpandedBlockStart.gif
View Code
 
//
Problem 2013 A short problem
/*
Accept: 158 Submit: 452
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
The description of this problem is very short. Now give you a string(length N), and ask you the max sum of the substring which the length can't small than M.
Input
The first line is one integer T(T≤20) indicates the number of the test cases. Then for every case, the first line is two integer N(1≤N≤1000000) and M(1≤M≤N).
Then one line contains N integer indicate the number. All the number is between -10000 and 10000.
Output
Output one line with an integer.
Sample Input
2
5 1
1 -2 -2 -2 1
5 2
1 -2 -2 -2 1
Sample Output
1
-1
*/
#include
"
iostream
"
using
namespace
std;
const
int
M
=
1000005
;
int
t,n,m;
int
i,j;
int
a[M];
int
sum[M];
int
f[M];
int
cmp(
int
a,
int
b)
{
return
a
>
b
?
a:b;
}
int
main()
{
scanf(
"
%d
"
,
&
t);
while
(t
--
)
{
scanf(
"
%d %d
"
,
&
n,
&
m);
for
(i
=
1
;i
<=
n;i
++
) scanf(
"
%d
"
,
&
a[i]);
int
i,Max
=-
0x7fffffff
;
sum[
0
]
=
0
;
for
(i
=
1
;i
<=
n;i
++
) sum[i]
=
sum[i
-
1
]
+
a[i];
f[m
-
1
]
=
sum[m
-
1
];
for
(i
=
m; i
<=
n; i
++
)
{
f[i]
=
cmp( f[i
-
1
]
+
a[i], sum[i]
-
sum[i
-
m]);
if
(f[i]
>
Max) Max
=
f[i];
}
printf(
"
%d\n
"
,Max);
}
return
0
;
}

转载于:https://www.cnblogs.com/FCWORLD/archive/2011/04/21/2023616.html

你可能感兴趣的文章
IO流的学习--文件夹下文件的复制
查看>>
第十六章:脚本化HTTP
查看>>
EXCEL表中如何让数值变成万元或亿元
查看>>
nginx在响应request header时候带下划线的需要开启的选项
查看>>
Linux下DHCP服务器配置
查看>>
AndroidStudio中导入SlidingMenu报错解决方案
查看>>
编写高性能的java程序
查看>>
Spring 的配置详解
查看>>
linux已经不存在惊群现象
查看>>
上位机和底层逻辑的解耦
查看>>
关于微信二次分享 配置标题 描述 图片??
查看>>
springcloud使用zookeeper作为config的配置中心
查看>>
校园火灾Focue-2---》洗手间的一套-》电梯
查看>>
bzoj1913
查看>>
L104
查看>>
分镜头脚本
查看>>
链表基本操作的实现(转)
查看>>
邮件发送1
查看>>
[转] libcurl异步方式使用总结(附流程图)
查看>>
编译安装LNMP
查看>>