Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Collection;
- import java.util.Arrays;
- import java.util.Scanner;
- public class MAin {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int x = sc.nextInt();
- int[] weights = new int[n];
- for(int i = 0; i < n; i++) {
- weights[i] = sc.nextInt();
- }
- Arrays.sort(weights);
- int S = 0, E = n - 1;
- int gondoli = 0;
- while(S <= E) {
- if(weights[S] + weights[E] <= x) {
- S++;
- E--;
- }
- else {
- E--;
- }
- gondoli++;
- }
- System.out.println(gondoli);
- }
- }
- // 158
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement