首页 > 代码库 > Codeforces Round #249 (Div. 2) A - Queue on Bus Stop

Codeforces Round #249 (Div. 2) A - Queue on Bus Stop

水题

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,m;
    cin >> n >> m;
    int cnt = 0, sum = 0;
    for(int i = 0 ; i < n; ++ i){
        int a;
        cin >> a;
        if(sum + a > m){
            cnt++;
            sum = a;
        }else if(sum+a == m){
            cnt++;
            sum = 0;
        }else{
            sum +=a;
        }
    }
    if(sum > 0) cnt++;
    cout<<cnt<<endl;
}