[CF1316A] Grade Allocation - 贪心

每个学生的分数最少为 \(0\),所以我们只要把除了第 \(1\) 名学生之外的所有学生的分数全部给第 \(1\) 个学生就能使他的分数最大。

#include <bits/stdc++.h>
using namespace std;

int n,m,a,t,s,w;

signed main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>n>>m;
        int x;
        s=0;
        for(int i=1;i<=n;i++) {
            cin>>x;
            if(i==1) w=x;
            else s+=x;
        }
        cout<<min(m,s+w)<<endl;
    }
}

猜你喜欢

转载自www.cnblogs.com/mollnn/p/12460172.html