Problem:
Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

//encoded utf-8
//tested with jdk 11

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //br.readLine(); return String one line.
        //Integer.parseInt(); String to Integer(Primitive).
        //String[] hoge = str.split(" ", 0);
        String[] NX = br.readLine().split(" ", 0);
        String[] aStr = br.readLine().split(" ", 0);
        LinkedList<Integer> a = new LinkedList<>();
        for(int i = 0; i < Integer.parseInt(NX[0]); i++){
            a.add(Integer.parseInt(aStr[i]));
        }
        a = sort(a);
        System.out.println(a);
        int X = Integer.parseInt(NX[1]);
        int counter = 0;
        for(int i = 0; i < Integer.parseInt(NX[0]); i++) {
            X -= a.get(i);
            if(X < 0){
                break;
            }
            counter ++;
        }
        if(X > 0) counter --;
        System.out.println(counter);
    }

    public static LinkedList<Integer> sort(LinkedList<Integer> linkedList){
        //conquer finish
        if(linkedList.size() <= 1){
            return linkedList;
        }
        //pivot select
        Random rmg = new Random();
        int pivId = rmg.nextInt(linkedList.size());
        //divide
        LinkedList<Integer> leftPart = new LinkedList<Integer>();
        LinkedList<Integer> rightPart = new LinkedList<Integer>();
        int temp = linkedList.get(pivId);
        //left and right added
        for(int i = 0; i < linkedList.size(); i ++){
            if(i == pivId){
                leftPart.add(linkedList.get(i));
                continue;
            }
            if(linkedList.get(i) < temp){
                leftPart.add(linkedList.get(i));
            } else{
                rightPart.add(linkedList.get(i));
            }
        }
        //conquer
        leftPart = sort(leftPart);
        rightPart = sort(rightPart);
        //combine to one linkedlist
        for(int i = 0; i < leftPart.size(); i ++){
            linkedList.set(i, leftPart.get(i));
        }
        for(int i = leftPart.size(); i < linkedList.size(); i ++){
            linkedList.set(i, rightPart.get(i - leftPart.size()));
        }
        return linkedList;
    }
}