?
№ | Отправитель | Задача | Язык | Вердикт | Время | Память | Отослано | Протест. | |
---|---|---|---|---|---|---|---|---|---|
193939801 |
Дорешивание: RahulAhuja2901 |
1561C - 12 | Java 8 | Ошибка исполнения на тесте 14 | 218 мс | 0 КБ | 2023-02-17 02:34:42 | 2023-02-17 02:34:42 |
import java.io.*; import java.util.*; import java.util.StringTokenizer; import javafx.util.Pair; public class Deep_Down_Below { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static long gcd (long a, long b) { if (b == 0) { return a; } return gcd (b, a % b); } public static long lcm (long a, long b) { long hcf = gcd (a, b); return (a * b) / hcf; } public static void SortByColumn (long arr[][]) { Arrays.sort (arr, new Comparator<long[]> () { public int compare (long[] arr1, long[] arr2) { if (arr1[0] > arr2[0]) { return 1; } else if (arr1[0] < arr2[0]) { return -1; } else { if (arr1[1] > arr2[1]) { return 1; } else { return -1; } } } }); } public static long sqrtl (long n) { long low = 0, high = (long)1e10, ans = -1; while (low <= high) { long mid = (low + high) / 2; if (mid * mid <= n) { ans = mid; low = mid + 1; } else { high = mid - 1; } } return ans; } public static boolean func (long[][] arr, long num) { int n = arr.length, i; for (i=0;i<n;i++) { if (num >= arr[i][0]) { num += arr[i][1]; } else { return false; } } return true; } public static PrintWriter out; public static void main (String[] args) throws java.lang.Exception { PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); /*try {*/ //Scanner obj = new Scanner (System.in); Reader obj = new Reader (); int t = obj.nextInt(); while (t > 0) { t--; int n = obj.nextInt(); //long n = obj.nextLong(); //String str = obj.next(); //char ch[] = str.toCharArray(); //int arr[] = new int[n]; long arr[][] = new long[n][2]; //ArrayList<Integer> arr = new ArrayList<Integer>(n); //ArrayList<Long> arr = new ArrayList<Long>(n); //HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); //HashMap<Long, Long> map = new HashMap<Long, Long>(); //Set<Integer> set = new HashSet<Integer>(); //Set<Long> set = new HashSet<Long>(); //Set<Character> set = new HashSet<Character>(); int i, j; for (i=0;i<n;i++) { long k = obj.nextLong(); long max = -1; for (j=0;j<k;j++) { long num = obj.nextLong(); max = Math.max (max, num + 1 - j); } arr[i][0] = max; arr[i][1] = k; } SortByColumn (arr); long low = 0, high = (long)1e10, ans = -1; while (low <= high) { long mid = (low + high) / 2; if (func (arr, mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } out.println (ans); } /*}catch(Exception e){ return; }*/ out.flush(); out.close(); } }
?
?
?
?