Advertisement
Josif_tepe

Untitled

May 7th, 2022
828
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Collection;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class MAin {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         int n = sc.nextInt();
  9.         int x = sc.nextInt();
  10.         int[] weights = new int[n];
  11.  
  12.         for(int i = 0; i < n; i++) {
  13.             weights[i] = sc.nextInt();
  14.         }
  15.         Arrays.sort(weights);
  16.         int S = 0, E = n - 1;
  17.         int gondoli = 0;
  18.         while(S <= E) {
  19.             if(weights[S] + weights[E] <= x) {
  20.                 S++;
  21.                 E--;
  22.             }
  23.             else {
  24.                 E--;
  25.             }
  26.             gondoli++;
  27.         }
  28.         System.out.println(gondoli);
  29.     }
  30. }
  31. // 158
Advertisement
RAW Paste Data Copied
Advertisement