ABC 题解但只有 ABC
2026-06-07 06:18:38
发布于:浙江
理由:ABC 只会出前缀和,滚-蛋-不-做-了。E 能做但是代码能力飞舞怕打不完还是不做了。
A
太水不讲
B
签到不讲
C
为啥很多人想 C 想了很久,反正我是一眼想出来了。
首先我们要取 种颜色,为了保证最优我们肯定要取每种颜色价值最高的那一个。接下来取剩下宝石的前 大即可。
我们用三个 vector 数组来做,分别维护每种颜色的宝石价值,每种颜色的最大宝石价值,除去每种颜色的最大宝石价值之外的其余宝石价值。先将每种宝石价值颜色降序排列,取第一个放入
数组中,其余的放入 数组中,注意判空。然后将 数组中的宝石价值累加。最后将 数组降序排列并计算前 个的宝石价值即可。
#include <bits/stdc++.h>
#define int long long
int max(int a,int b){
return a>b?a:b;
}int n,m,k,ans=0,flag=0;
std::vector<int> a[200005],cnt,first;
signed main(){
std::cin >> n >> k >> m;
for(int i=1;i<=n;i++){
int c,val;
std::cin >> c >> val;
a[c].push_back(val);
}for(int i=1;i<=n;i++){
if(a[i].empty())continue;
std::sort(a[i].begin(),a[i].end(),std::greater<int>());
first.push_back(a[i][0]);
for(int j=1;j<a[i].size();j++)cnt.push_back(a[i][j]);
}
std::sort(first.begin(),first.end(),std::greater<int>());
for(int i=0;i<m;i++){
ans+=first[i];
}for(int i=m;i<first.size();i++)cnt.push_back(first[i]);
std::sort(cnt.begin(),cnt.end(),std::greater<int>());
for(int i=0;i<k-m;i++)ans+=cnt[i];
std::cout << ans;
}
全部评论 2
D的pref?unordered_set ? ! 不会写?放弃? ?!ppl ?!
1周前 来自 浙江
0完了ppl
1周前 来自 浙江
0D 唐人 ppl 尝试使用 umap 水过硬吃 5 罚 TLE,然后尝试优化 WA 1 罚
1周前 来自 广东
0毅力很强的/确信
1周前 来自 浙江
0
d
1周前 来自 浙江
0

















有帮助,赞一个