/
Ersh
/
homeworkAlgo1
Обзор
Документация
Войти
/
Ersh
/
homeworkAlgo1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
36 строк
998 B
Ersh
upload files
19 ноя 2025, 19:56
19 ноя 2025, 19:56
79bfadf
Код
Авторство
О чём код?
public class Main { public static void main(String[] args) { int[] prices = { 13, 17, 19, 25, 25, 25, 25, 25, 25, 27, 30 }; System.out.println("Для 31: " + countMore(prices, 31)); // 0 System.out.println("Для 26: " + countMore(prices, 26)); // 2 System.out.println("Для 25: " + countMore(prices, 25)); // 2 System.out.println("Для 20: " + countMore(prices, 20)); // 8 } public static int countMore(int[] prices, int money) { if (prices[0] > money) { return prices.length; } if (prices[prices.length - 1] <= money) { return 0; } int left = 0; int right = prices.length - 1; while (left < right) { int middle = left + (right - left) / 2; if (prices[middle] > money) { right = middle; } else { left = middle + 1; } } return prices.length - left; } }