Submission #2546190
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import javafx.util.Pair; public class Main { private static Scanner sc; private static int[][] neg8 = new int[][]{{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}}; private static int[][] neg4 = new int[][]{{1, 0}, {0, -1}, {-1, 0}, {0, 1}}; public static void main(String[] args) { Main instance = new Main(); sc = instance.new Scanner(); instance.solve(); } private void solve() { try { int N=sc.nextInt(); long K=sc.nextLong(); long[] as = new long[N]; long[] bs = new long[N]; PriorityQueue<Pair<Long, Integer>> q = new PriorityQueue<>(new Comparator<Pair<Long, Integer>>() { @Override public int compare(Pair<Long, Integer> o1, Pair<Long, Integer> o2) { return (int) (o1.getKey() - o2.getKey()); } }); for (int i = 0; i < N; i++) { as[i]=sc.nextLong(); bs[i]=sc.nextLong(); q.add(new Pair<>(as[i], i)); } long ans = 0; for (int i = 0; i < K; i++) { Pair<Long, Integer> poll = q.poll(); ans += poll.getKey(); q.add(new Pair<>(poll.getKey() + bs[poll.getValue()], poll.getValue())); } System.out.println(ans); } catch (Exception e) { e.printStackTrace(); } } private class Scanner { String[] s; int i; BufferedReader br; String regex = " "; public Scanner() { s = new String[0]; i = 0; br = new BufferedReader(new InputStreamReader(System.in)); } @Override protected void finalize() throws Throwable { try { super.finalize(); } finally { destruction(); } } private void destruction() throws IOException { if (br != null) br.close(); } public String next() throws IOException { if (i < s.length) return s[i++]; String st = br.readLine(); while (st == "") st = br.readLine(); s = st.split(regex, 0); i = 0; return s[i++]; } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } public Long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } public Double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } } private static double distance(int x1, int x2, int y1, int y2) { return Math.sqrt((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))); } private static boolean nextPermutation(int[] nums) { int i = nums.length - 2; while (i >= 0 && nums[i + 1] <= nums[i]) { i--; } boolean swap = false; if (i >= 0) { int j = nums.length - 1; while (j >= 0 && nums[j] <= nums[i]) { j--; } swap(nums, i, j); swap = true; } reverse(nums, i + 1); return swap; } private static void reverse(int[] nums, int start) { int i = start, j = nums.length - 1; while (i < j) { swap(nums, i, j); i++; j--; } } private static void swap(int[] nums, int i, int j) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } private static ArrayList filledList(int n, int fill) { return new ArrayList<>(Collections.nCopies(n, fill)); } // 指定した値`以上`の要素が最初に現れる位置を返す private static int lower_bound(List<Integer> list, int val) { return ~Collections.binarySearch(list, val, (x, y) -> x.compareTo(y) >= 0 ? 1 : -1); } // 指定した値`より大きい`の要素が最初に現れる位置を返す private static int upper_bound(List<Integer> list, int val) { return ~Collections.binarySearch(list, val, (x, y) -> x.compareTo(y) > 0 ? 1 : -1); } }
Submission Info
Submission Time | |
---|---|
Task | C - Factory |
User | jun0sck |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 4601 Byte |
Status | CE |
Compile Error
./Main.java:5: error: package javafx.util does not exist import javafx.util.Pair; ^ ./Main.java:26: error: cannot find symbol PriorityQueue<Pair<Long, Integer>> q = new PriorityQueue<>(new Comparator<Pair<Long, Integer>>() { ^ symbol: class Pair location: class Main ./Main.java:26: error: cannot find symbol PriorityQueue<Pair<Long, Integer>> q = new PriorityQueue<>(new Comparator<Pair<Long, Integer>>() { ^ symbol: class Pair location: class Main ./Main.java:28: error: cannot find symbol public int compare(Pair<Long, Integer> o1, Pair<Long, Integer> o2) { ^ symbol: class Pair ./Main.java:28: error: cannot find symbol public int compare(Pair<Long, Integer> o1, Pair<Long, Integer> o2) { ^ symbol: class Pair ./Main.java:35...