信息学奥赛一本通1075:药房管理

地址:http://ybt.ssoier.cn:8088/problem_show.php?pid=1075

这题可以使用循环结构写,使用cnt变量来存储未取药的病人。

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int m,n,s,cnt;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>m;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s;
        if(m<s) cnt++;
        else m-=s;
    }
    cout<<cnt<<endl;
    return 0;
}

 

posted @ 2025-01-04 13:27  Spark1024  阅读(108)  评论(0)    收藏  举报