結果
問題 |
No.2774 Wake up Record 2
|
ユーザー |
![]() |
提出日時 | 2024-06-07 21:50:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 737 ms / 2,000 ms |
コード長 | 862 bytes |
コンパイル時間 | 2,367 ms |
コンパイル使用メモリ | 77,548 KB |
実行使用メモリ | 52,128 KB |
最終ジャッジ日時 | 2024-12-26 07:45:38 |
合計ジャッジ時間 | 9,903 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); int ok = 1000000001; int ng = 0; while (Math.abs(ok - ng) > 1) { int mid = (ok + ng) / 2; int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] < mid) { cnt++; } } if (cnt >= k) { ok = mid; } else { ng = mid; } } int cnt = 0; StringBuilder sb = new StringBuilder(); for (int i = 1; i < n; i++) { if (a[i - 1] < ok && a[i] >= ok) { cnt++; sb.append(i + 1).append(' '); } } if (cnt > 0) { sb.deleteCharAt(sb.length() - 1); } System.out.println(cnt); System.out.println(sb.toString()); } }