Submission #19550182
Source Code Expand
Copy
import java.io.IOException; import java.io.InputStream; import java.util.Comparator; import java.util.NoSuchElementException; import java.util.PriorityQueue; import java.util.Queue; public class Main { //static int mod = 1000000007; static int mod = 998244353; static int inf = (Integer.MAX_VALUE-1); static long infL = 0xfffffffffffffffL; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); long[] times = new long[n]; int[] b = new int[n]; for(int i = 0; i < n; i++) { times[i] = sc.nextInt(); b[i] = sc.nextInt(); } Queue<Integer> q = new PriorityQueue<>(Comparator.comparing(i -> times[i])); for(int i = 0; i < n; i++) { q.add(i); } long ans = 0; for(int i = 0; i < k; i++) { int j = q.poll(); ans += times[j]; times[j] += b[j]; q.add(j); } System.out.println(ans); } private static int binarySearch2D(long key, long[][] ps, int ind, int fromIndex, int toIndex) { int low = fromIndex; int high = toIndex - 1; while (low <= high) { int mid = (low + high) >>> 1; long midVal = ps[mid][ind]; if (midVal < key) low = mid + 1; else if (midVal > key) high = mid - 1; else return mid; // key found } return -(low + 1); // key not found. } private static long modpow(int b, int e, int m) { long result = 1; while(e > 0) { if((e&1) == 1) result = (result * b) % m; e >>= 1; b = (b*b) % m; } return result; } } class Pair{ int v; long h; public Pair(int v, long h) { this.v = v; this.h = h; } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; public FastScanner(InputStream in2) { // TODO 自動生成されたコンストラクター・スタブ } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }
Submission Info
Submission Time | |
---|---|
Task | C - Factory |
User | kiruto398 |
Language | Java (OpenJDK 11.0.6) |
Score | 300 |
Code Size | 3946 Byte |
Status | AC |
Exec Time | 327 ms |
Memory | 58804 KB |
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 | sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 76 ms | 33272 KB |
sample_02.txt | AC | 153 ms | 51008 KB |
sample_03.txt | AC | 88 ms | 33308 KB |
subtask_1_1.txt | AC | 89 ms | 33660 KB |
subtask_1_10.txt | AC | 232 ms | 55328 KB |
subtask_1_11.txt | AC | 80 ms | 33324 KB |
subtask_1_12.txt | AC | 176 ms | 53980 KB |
subtask_1_13.txt | AC | 80 ms | 33372 KB |
subtask_1_14.txt | AC | 212 ms | 53788 KB |
subtask_1_15.txt | AC | 327 ms | 58152 KB |
subtask_1_16.txt | AC | 115 ms | 35252 KB |
subtask_1_17.txt | AC | 92 ms | 33500 KB |
subtask_1_18.txt | AC | 265 ms | 58804 KB |
subtask_1_2.txt | AC | 214 ms | 44364 KB |
subtask_1_3.txt | AC | 136 ms | 42444 KB |
subtask_1_4.txt | AC | 173 ms | 37392 KB |
subtask_1_5.txt | AC | 195 ms | 51108 KB |
subtask_1_6.txt | AC | 226 ms | 52832 KB |
subtask_1_7.txt | AC | 133 ms | 34944 KB |
subtask_1_8.txt | AC | 278 ms | 54924 KB |
subtask_1_9.txt | AC | 313 ms | 57496 KB |