int[] prefix = newint[n]; int[] suffix = newint[n]; for (intk=0; k < n; k++) { Strings= io.next();
for (inti=0; i < s.length() && prefix[k] < t.length(); i++) { if (s.charAt(i) == t.charAt(prefix[k])) { prefix[k]++; } }
for (inti=0; i < s.length() && suffix[k] < t.length(); i++) { if (s.charAt(s.length() - 1 - i) == t.charAt(t.length() - 1 - suffix[k])) { suffix[k]++; } } }
Arrays.sort(suffix);
longans=0L; for (inti=0; i < n; i++) { intlo=0, hi = n - 1; while (lo <= hi) { intmid= lo + (hi - lo) / 2; if (prefix[i] + suffix[mid] >= t.length()) hi = mid - 1; else lo = mid + 1; } ans += n - lo; } io.println(ans); }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt();
int[] in = newint[n]; List<int[]>[] g = newList[n]; Arrays.setAll(g, k -> newArrayList<>()); for (inti=0; i < m; i++) { intu= io.nextInt() - 1, v = io.nextInt() - 1, b = io.nextInt(), c = io.nextInt(); g[u].add(newint[]{v, b, c}); in[v]++; }
doublelo=0, hi = 1e4; while (hi - lo >= 1e-10) { doublemid= lo + (hi - lo) / 2; if (check(g, in.clone(), mid)) lo = mid; else hi = mid; } io.println(lo); }
dist[0] = 0; for (intu=0; u < n; u++) { for (int[] t : g[u]) { intv= t[0], b = t[1], c = t[2]; if (dist[v] < dist[u] + b - c * x) { dist[v] = dist[u] + b - c * x; } } }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt(); Strings= io.next(), t = io.next(); intans=0; for (inti=0; i < n; i++) { if (s.charAt(i) != t.charAt(i)) { ans |= 2; } if (s.charAt(i) != t.charAt(m - n + i)) { ans |= 1; } } io.println(ans); }
publicstaticvoidsolve() { intn= io.nextInt(), x = io.nextInt(); intmin=101, max = -1, sum = 0; for (inti=0; i < n - 1; i++) { intt= io.nextInt(); sum += t; min = Math.min(min, t); max = Math.max(max, t); } intt= x - (sum - min - max); if (t > max) { io.println(-1); } else { io.println(t <= min ? 0 : t); } }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt(), p = io.nextInt(); int[] a = newint[n]; for (inti=0; i < n; i++) { a[i] = io.nextInt(); } int[] b = newint[m]; for (inti=0; i < m; i++) { b[i] = io.nextInt(); } Arrays.sort(b); long[] sum = newlong[m + 1]; for (inti=0; i < m; i++) { sum[i + 1] = sum[i] + b[i]; } longans=0L; for (inti=0; i < n; i++) { intx= p - a[i]; intlo=0, hi = m - 1; while (lo <= hi) { int mid= lo + (hi - lo) / 2; if (b[mid] <= x) lo = mid + 1; else hi = mid - 1; } ans += ((long) lo * a[i] + sum[lo]) + (long) (m - lo) * p; } io.println(ans); }