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 Go (1.6) (judge verdict: Wrong Answer)

package main

import (
        "bufio"
        "fmt"
        "os"
        "sort"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int64 {
        n, _ := strconv.ParseInt(str, 10, 64)
        return n
}

func intSprit(str string) []int64 {
        strs := strSprit(str)
        cols := make([]int64, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

type int64s []int64

func (s int64s) Len() int {
        return len(s)
}
func (s int64s) Less(i, j int) bool {
        return s[i] < s[j]
}
func (s int64s) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func main() {
        line := readBigLine()

        spln := intSprit(line)

        N := spln[0]
        x := spln[1]

        ln := readBigLine()
        a := intSprit(ln)

        sort.Sort(int64s(a))
        c := 0
        for i := int64(0); i < N; i++ {
                if x <= 0 {
                        break
                }
                if x-a[i] < 0 {
                        break
                }
                x -= a[i]
                c++
        }
        if c > 0 && x != 0 {
                c--
        }
        fmt.Println(c)
}