publicstaticvoidsolve() { intx= io.nextInt(), y = io.nextInt(), n = io.nextInt(); intz= (1 + n - 1) * (n - 1) / 2; if (z > y - x) { io.println(-1); return; } io.print(x + " "); intd= x + y - x - z; for (inti= n - 1; i >= 1; i--) { d += i; io.print(d + " "); } io.println(); }
publicstaticvoidsolve() { intn= io.nextInt(), h = io.nextInt(), x = io.nextInt(); int[] p = newint[n]; for (inti=0; i < n; i++) { p[i] = io.nextInt(); } x = x - h;
intlo=0, hi = n - 1; while (lo <= hi) { intmid= lo + (hi - lo) / 2; if (p[mid] < x) lo = mid + 1; else hi = mid - 1; } io.println(lo + 1); }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt();
List<int[]>[] g = newList[n]; Arrays.setAll(g, k -> newArrayList<>()); for (inti=0; i < m; i++) { intu= io.nextInt() - 1, v = io.nextInt() - 1, w = io.nextInt(); g[u].add(newint[]{v, w}); g[v].add(newint[]{u, w}); }
boolean[] vis = newboolean[n]; for (inti=0; i < n; i++) { dfs(i, 0, g, vis); } io.println(ans); }
privatestaticvoiddfs(int x, int dis, List<int[]>[] g, boolean[] vis) { vis[x] = true; ans = Math.max(ans, dis); for (int[] t : g[x]) { inty= t[0], w = t[1]; if (!vis[y]) { dfs(y, dis + w, g, vis); } } vis[x] = false; }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt(), d = io.nextInt(); int[] a = newint[n]; for (inti=0; i < n; i++) a[i] = io.nextInt(); PriorityQueue<Integer> q = newPriorityQueue<>(); longsum=0L, ans = 0L; for (inti=0; i < n; i++) { if (a[i] <= 0) continue; q.offer(a[i]); sum += a[i]; if (q.size() > m) sum -= q.poll(); ans = Math.max(ans, sum - (long) d * (i + 1)); } io.println(ans); }