每个学生的分数最少为 \(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;
- }
- }
[CF1316A] Grade Allocation - 贪心
来源: http://www.bubuko.com/infodetail-3456267.html