1 solutions

  • 0
    @ 2025-4-8 10:33:31

    按照题意模拟即可

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int N,K;
        cin>>N>>K;
        int x=0,z=0;
        for(int i=0;i<N;i++){
            int y;
            cin>>y;
            x=x+y;
            if(x>K){
                z=z+1;
                x=y;
            }
            if(x==K){
                z=z+1;
                x=0;
            }
    
        }
        if(x!=0) z++;
        cout<<z<<endl;
    
    }
    
    • 1

    Information

    ID
    1454
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    # Submissions
    273
    Accepted
    39
    Uploaded By