CSP 202109-1 数值推导

答题

 一眼看上去好像有点复杂,稍微想一下就知道,最大值就是把所有B加起来,最小值就是把不重复的B加起来,用set搞定不重复的元素

#include<iostream>
#include<set>
using namespace std;
int main(){
    int n,max=0,min=0,temp;
    set<int>A;
    cin>>n;
    while(n--){
        cin>>temp;
        max+=temp;
        A.insert(temp);
    }
    for(auto&it:A){
        min+=it;
    }
    cout<<max<<endl<<min;
}

猜你喜欢

转载自blog.csdn.net/weixin_62264287/article/details/132816931
CSP