CF1662A Organizing SWERC 题解
文章目录
题目链接
题目大意:
有 n n n 个问题,这些问题有两个属性,一个是难度 d i d_i di,和美学值 b i b_i bi。满足 1 ≤ d i , b i ≤ 10 1 \le d_i,b_i \le 10 1≤di,bi≤10。现在请你选出一些题目,使得在每种难度的题目都有,且仅有一道的条件下,使得最后的美学值的和最大。若题目凑不出所有难度,则输出 MOREPROBLEMS。
思路:
在输入的过程中统计每种难度的题目,贪心选择美学值最大的。记得清空记录的数组。
代码:
#include<bits/stdc++.h>
using namespace std;
int t,a[11];
int main(){
cin>>t;
while(t--){
int n,ans=0,shi=0;
cin>>n;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
if(!a[y]){
ans+=x;
shi++;
a[y]=x;
}
else if(a[y]<x){
ans+=x-a[y];
a[y]=x;
}
}
if(shi==10){
cout<<ans<<endl;
}
else{
cout<<"MOREPROBLEMS\n";
}
memset(a,0,sizeof a);
}
}