题解:P10291 [CCC 2024 J2] Dusa And The Yobis

· · 题解

思路:

先输入,然后模拟,当 Yobi 的大小大于等于 Dusa 时输出 Dusa 现在的大小,并结束。

因为题目没有告诉我们有几个 Yobi 所以这样输入:

while(cin>>a[cnt++]);

代码:

#include<bits/stdc++.h>
#define LL long long
#define CPPname using namespace std
CPPname;
LL Dusa;
int cnt=1,a[200010];
int main(){
    int d;cin>>d;
    Dusa=d;
    while(cin>>a[cnt++]);
    for(int i=1;i<cnt;i++){
        if(Dusa>a[i])Dusa+=a[i];
        else{
            cout<<Dusa;
            return 0;
        }
    }
    return 0;
}