CF1662A Organizing SWERC 题解
- 题目大意:
- 思路:
- 代码:
题目链接
题目大意:现在有 n n n 个问题,这些问题有两个属性,一个是美学值 b i b_i bi,和难度 d i d_i di。满足 1 ≤ b i , d i ≤ 10 1 le b_i,d_i le 10 1≤bi,di≤10。现在请你选出一些题目,使得在每种难度的题目都有,且仅有一道的条件下,使得最后的美学值的和最大。若给出的题目凑不出所有难度,则输出 MOREPROBLEMS 。
思路:在输入的过程中统计每种难度的题目,贪心选择美学值最大的。记得清空记录的数组。
代码:#includeusing 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] ans+=x-a[y]; a[y]=x; } } if(shi==10){ cout< cout<<"MOREPROBLEMSn"; } memset(a,0,sizeof a); } }



