Submission #76442128
Source Code Expand
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define inf 1e18
#define eps 1e-9
#define endl "\n"
#define il inline
#define ls 2*k
#define rs 2*k+1
using namespace std;
const int N=2e5+5,M=2505;
const int mod=1e9+7;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
bool vis[N],in[N];
int n,k,m;
pair<int,int>a[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc=1;
while(tc--){
cin>>n>>k>>m;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
a[i]={y,x};
}
sort(a+1,a+n+1,greater< pair<int,int> >());
int ans=0,cnt=0,ret=0;
for(int i=1;i<=n;i++){
if(!vis[a[i].second]){
ans+=a[i].first;
ret++,vis[a[i].second]=1,cnt++;
in[i]=1;
}
if(cnt>=m || ret>=k) break;
}
for(int i=1;i<=n;i++){
if(ret>=k) break;
if(in[i]) continue;
ans+=a[i].first,ret++;
}
cout<<ans<<'\n';
}
return 0;
}
/*
*/
Submission Info
| Submission Time | |
|---|---|
| Task | C - Variety |
| User | Limingxuan |
| Language | C++23 (GCC 15.2.0) |
| Score | 300 |
| Code Size | 1149 Byte |
| Status | AC |
| Exec Time | 29 ms |
| Memory | 7120 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample-01.txt, sample-02.txt, sample-03.txt |
| All | 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, sample-01.txt, sample-02.txt, sample-03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 04.txt | AC | 1 ms | 3416 KiB |
| 05.txt | AC | 17 ms | 6728 KiB |
| 06.txt | AC | 17 ms | 7120 KiB |
| 07.txt | AC | 21 ms | 6764 KiB |
| 08.txt | AC | 1 ms | 3432 KiB |
| 09.txt | AC | 1 ms | 3560 KiB |
| 10.txt | AC | 1 ms | 3724 KiB |
| 11.txt | AC | 11 ms | 4796 KiB |
| 12.txt | AC | 28 ms | 7056 KiB |
| 13.txt | AC | 28 ms | 6888 KiB |
| 14.txt | AC | 28 ms | 6888 KiB |
| 15.txt | AC | 28 ms | 6952 KiB |
| 16.txt | AC | 28 ms | 7056 KiB |
| 17.txt | AC | 29 ms | 7008 KiB |
| 18.txt | AC | 27 ms | 7072 KiB |
| 19.txt | AC | 28 ms | 6844 KiB |
| 20.txt | AC | 28 ms | 7000 KiB |
| 21.txt | AC | 28 ms | 6616 KiB |
| 22.txt | AC | 28 ms | 7120 KiB |
| 23.txt | AC | 28 ms | 6844 KiB |
| sample-01.txt | AC | 1 ms | 3432 KiB |
| sample-02.txt | AC | 1 ms | 3552 KiB |
| sample-03.txt | AC | 1 ms | 3396 KiB |