提出 #76461406


ソースコード 拡げる

import java.util.*;

public class Main{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int k = sc.nextInt();
	    int m = sc.nextInt();
	    HashMap<Integer, PriorityQueue<Integer>> map = new HashMap<>();
	    
	    for(int i = 0; i<n; i++){
	        int c = sc.nextInt();
	        int v = sc.nextInt();
	        
	        if(!map.containsKey(c)) map.put(c, new PriorityQueue<>(Collections.reverseOrder()));
	        map.get(c).add(v);
	    }
	    
	    long res = 0;
	    k -= m;
	    
	    PriorityQueue<Integer> all = new PriorityQueue<>(Collections.reverseOrder());
	    
	    for(int key : map.keySet()){
	        all.add(map.get(key).remove());
	    }
	    
	    while(m-- > 0){
	        res += all.remove();
	    }
	     
	    for(int key : map.keySet()){
	         PriorityQueue<Integer> pq = map.get(key);
	         while(!pq.isEmpty()){
	             all.add(pq.remove());
	         }
	    }
	    
	    while(k-- > 0){
	        res += all.remove();
	    }
	    
		System.out.println(res);
	}
}

提出情報

提出日時
問題 C - Variety
ユーザ jayeshsolanki
言語 Java24 (OpenJDK 24.0.2)
得点 300
コード長 1116 Byte
結果 AC
実行時間 925 ms
メモリ 101440 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 23
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
04.txt AC 78 ms 39904 KiB
05.txt AC 622 ms 72024 KiB
06.txt AC 717 ms 101116 KiB
07.txt AC 724 ms 86444 KiB
08.txt AC 76 ms 40532 KiB
09.txt AC 113 ms 42344 KiB
10.txt AC 146 ms 48200 KiB
11.txt AC 595 ms 77356 KiB
12.txt AC 898 ms 90940 KiB
13.txt AC 911 ms 91080 KiB
14.txt AC 925 ms 91096 KiB
15.txt AC 872 ms 83488 KiB
16.txt AC 800 ms 82192 KiB
17.txt AC 795 ms 83936 KiB
18.txt AC 814 ms 82604 KiB
19.txt AC 850 ms 87036 KiB
20.txt AC 816 ms 83896 KiB
21.txt AC 889 ms 93284 KiB
22.txt AC 693 ms 101440 KiB
23.txt AC 845 ms 88164 KiB
sample-01.txt AC 75 ms 40328 KiB
sample-02.txt AC 71 ms 40024 KiB
sample-03.txt AC 73 ms 39892 KiB