容易想歪的简单题。
考虑社团人数上限很高,是 \(\lfloor\frac{n}{2}\rfloor\),很容易发现,其实两个社团就可以塞满 \(n\) 个人。
于是对于一个人,只需考虑三个社团中的最大值和次大值,那么首先,如果按所有人都分配到对于那个人中三个社团最大值之后,人数最大的社团也是小于等于 \(\lfloor\frac{n}{2}\rfloor\) 的话,那么答案直接就是将所有人对应的最大值加起来就行了,设这个值为 \(sum\),否则的话,考虑如何微调。
那么考虑一个人的贡献,其实可以设成他的最大值和次大值的差,然后按贡献从小到大排序,容易证明这是对的。
然后其实考虑我们设目前人数超过 \(\lfloor\frac{n}{2}\rfloor\) 的社团人数和 \(\lfloor\frac{n}{2}\rfloor\) 的差为 \(s\),然后删掉前 \(s\) 个人的贡献就行了。
代码:
[code]#includeusing namespace std;const int N = 1e5+5;struct node{ int x; int y; int z; int maxxx; int cha;}a[N];int num[3];int b[N];signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int _; cin >> _; while(_--) { num[0] = num[1] = num[2] = 0; int n,sum = 0; cin >> n; for(int i = 1;i> a.x >> a.y >> a.z; int maxx = a.x,maxxx = 0; if(a.y>maxx) { maxx = a.y; maxxx = 1; } if(a.z>maxx) { maxx = a.z; maxxx = 2; } int cmax; if(maxx == a.x) { if(a.y>a.z) { cmax = a.y; } else { cmax = a.z; } } else if(maxx == a.y) { if(a.x>a.z) { cmax = a.x; } else { cmax = a.z; } } else { if(a.x>a.y) { cmax = a.x; } else { cmax = a.y; } } a.maxxx = maxxx; a.cha = maxx-cmax; sum+=maxx; ++num[maxxx]; } int ss = 0; if(num[ss] |