Français
Ouvrir dans Telegram

Fil de discussion Message n° 2411

5 messages · –
  1. K
    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), k = sc.nextInt(), d = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); int count = 0; while (true) { int max = 0, min = 0, diff; for (int i = 0; i < n; i++) { if (a[i] > a[max]) { max = i; } if (a[i] < a[min]) { min = i; } } if (a[max]-a[min] <= d) { break; } while ((diff = a[max]-a[min]) > d) { a[max] -= Math.min((diff-d)/2, k); a[min] += Math.min((diff-d)/2, k); count++; } } System.out.println(count); } }
CCore Java | Java for BeginnersCore Java | Java for Beginners@codeitupjava · groupe · Technologie
1 312membres62écrivent en 30 jours
Fil de la communauté Ouvrir dans Telegram

Un fil public ouvert issu de l'index de recherche ChatCrawler — « le Google du Telegram public » ; actualisé à mesure que la communauté est explorée. Les heures sont en UTC.

Contenu public uniquement, API officielle de Telegram. À propos · FAQ · Limites de l'index · Retirer une page · Catalogue · Recherche · Comment nous comptons