70 累加出整个范围所有的数最少还需要几个数
Table of Contents

ac

import java.util.Arrays;
import java.util.Scanner;


public class Main {
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args){
        int n = sc.nextInt();
        int range = sc.nextInt();
        int[] arr = new int[n];
        int arrMin = Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
            int num = sc.nextInt();
            arr[i] = num;
            if(num < arrMin){
                arrMin = num;
            }
        }
        Arrays.sort(arr);

        int need = 0;
        int arrIndex = 0;
        int curRange = 0;
        // 肯定缺少1
        if(arrMin > 1){
            need ++;
            curRange = 1;
        }
        while (curRange < range && arrIndex < n){
            if(arr[arrIndex] <= curRange + 1){
                curRange = curRange + arr[arrIndex];
                arrIndex ++;
            }else {
                curRange = curRange + curRange + 1;
                need ++;
            }
        }
        if(curRange < range){
            need ++;
        }
        System.out.println(need);
    }

    static long getAns(int[] sortedArr, int n){
        // [1, range] 能够被 arr[0...i-1] 算出来
        // arr[i];
        // arr[i] > range + 1; 则不会出现sum为 range + 1 了,因为最小就是 arr[i] > range + 1
        // arr[i] <= range + 1; [1, range + arr[i]]
        long range = 0;
        for(int i=0;i<n;i++){
            if(sortedArr[i] > range + 1){
                return range + 1;
            }else {
                range = range + sortedArr[i];
            }
        }
        return range + 1;
    }
}
/*
4 15
1 2 3 7

1(14)

3 14
1 5 7

2(2,4)
 */