比赛 2026.9.5 评测结果 AAAEEWWWWWWWWWW
题目名称 Pretty Pens 最终得分 18
用户昵称 0814d 运行时间 1.274 s
代码语言 C++ 内存使用 5.00 MiB
提交时间 2026-09-05 11:22:09
显示代码纯文本
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n,m,q,ans;
int vis[200005];
struct node{
    int c,p;
}str[200005];
bool cmp(node a,node b){
    return a.p>b.p;
}
signed main(){
    freopen("Pens.in","r",stdin);
    freopen("Pens.out","w",stdout);
    cin>>n>>m>>q;
    if(q==0){
        for(int i=1;i<=n;i++){
            cin>>str[i].c>>str[i].p;
        }
        sort(str+1,str+n+1,cmp);
        int cnt=0,last,bian,d=0;
        for(int i=1;i<=n;i++){
            if(vis[str[i].c]==0){
                vis[str[i].c]+=1;
                ans+=str[i].p;
                last=i;
                cnt++;
            }else{
                if(d==0&&cnt<n){
                    bian=i;
                    d++;
                }
            }
        }
        ans-=str[last].p;
        ans+=str[bian].p;
        cout<<ans;
    }
    return 0;
}