题解:P11542 [Code+#5] 教室人数问题

· · 题解

把所有正数安排在前面,所有负数安排在后面。

如果 \sum a_i 非负,那么在累加的过程中一定不会出现负数。

否则所有数的和都是负数了也就没什么好说的了。

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    int s=0;
    while(n--){
        int x;cin>>x;
        s+=x;
    }
    if(s>=0)cout<<"Wo jue de OK";
    else cout<<"Wo jue de bu tai xing";
    return 0;
}