跳到正文

题解

题解 P1181 【数列分段Section I】

cjZYZtcl约 1 分钟
原文
文章信息与版本

文章信息

发布
2019年11月21日
收录
2025年12月26日
更新
2026年11月9日
篇幅
约 1 分钟
题目
P1181

版本

  1. v1当前

实际上这题就是一遍搜过去,如果超出一组的限制就累加一。

话不多说,直接上pascal代码:

pascal
var
  n,m,i,s,x:longint;
  a:array[0..100005]of longint;
begin
  readln(n,m);
  for i:=1 to n do read(a[i]);
  i:=1;
  while i<=n do
  begin
    if s+a[i]<=m then begin s:=s+a[i]; inc(i); end
    else begin s:=a[i]; inc(x); inc(i); end;
  end;
  write(x+1);
end.
原文