跳到正文

个人记录

5.19 做题记录

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

文章信息

发布
2024年5月19日
收录
2025年12月29日
更新
2026年11月16日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

「一本通 1.1 练习 2」数列分段 sdfzoj#96

C++
#include<stdc++.h>//bits/
using namespace std;
int n,l,sum,cnt = 1,a[100005];
int main(){
    cin>>n>>l;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
        if(sum + a[i] <= l){
            sum = sum + a[i];
        }
        else{
            sum = a[i];
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}
/*
7 5
3 8 9 12 13 14 18
*/

www.luogu.com.cn
原文