From 3b18366ca6cca93374ea2d9f612c8e87d2d36e5a Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 13 Sep 2016 15:23:01 +0800 Subject: [PATCH] Create 3017.cpp --- POJ/3017.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 POJ/3017.cpp diff --git a/POJ/3017.cpp b/POJ/3017.cpp new file mode 100644 index 0000000..e5a76d9 --- /dev/null +++ b/POJ/3017.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include +using namespace std; + +#define MAXN 1000100 +#define INF 0x3f3f3f3f + +long long a[MAXN]; +long long dp[MAXN]; + +long long t[MAXN]; +int tbegin,tend; + +int main() +{ + int N; + long long M; + scanf("%d %I64d",&N,&M); + tbegin=tend=0; + long long blocksum=0; + int blockbegin=0; + for(int i=1;i<=N;i++) + { + scanf("%I64d",&a[i]); + ///如果整个数列中任何一个数超过M,那么是无论如何都不能划分的(没有负数存在) + if(a[i]>M) + { + printf("-1\n"); + return 0; + } + blocksum+=a[i]; + while(blocksum>M) + { + ///如果现在假设的连续区块 ID: blockbegin, blockbegin+1 ... i + ///求和超过M,那么这是一个非法区块,需要减去最左端的区块(向右收缩) + blockbegin++;///【疑问】为什么blockbegin要在前面? + blocksum-=a[blockbegin]; + } + ///队列用于维护每个区块中最大的值的ID + while(tbegin