#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ quicksort(long *, int /*<<< orphan*/, long);
int /*<<< orphan*/ scanf(char *, long *, ...);
int main() {
  long int n, k, s = 0, i;
  int j, q;
  scanf("%ld %ld", &n, &k);
  long int a[n];
  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  quicksort(a, 0, n - 1);
  i = 0;
  while (s <= k) {
    s += a[i];
    i++;
  }
  printf("%ld", i - 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11c9 <main+0x99>
mov    -0x48(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    118d <main+0x5d>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
xor    %esi,%esi
call   1030 <quicksort@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     1217 <main+0xe7>
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11e4 <main+0xb4>
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rsp,%r12
mov    -0x30(%rbp),%rax
mov    %rsp,%r15
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x30(%rbp),%rdx
test   %rdx,%rdx
jle    11ae <main+0x7e>
lea    0xe81(%rip),%r14
mov    %r15,%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbx
mov    -0x30(%rbp),%rdx
add    $0x8,%r13
cmp    %rdx,%rbx
jl     1190 <main+0x60>
add    $0xffffffffffffffff,%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <quicksort@plt>
mov    -0x38(%rbp),%rax
mov    $0xffffffffffffffff,%rsi
test   %rax,%rax
js     11de <main+0xae>
xor    %ecx,%ecx
xchg   %ax,%ax
add    0x8(%r15,%rsi,8),%rcx
add    $0x1,%rsi
cmp    %rax,%rcx
jle    11d0 <main+0xa0>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%ld %ld\00"
@.str.1 = [4 x i8] c"%ld\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %4
%10 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64* %2, i64* %3)
%11 = load i64, i64* %2
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i64, i64 %11
store i64 %11, i64* %9
store i64 0, i64* %5
br label %14
14: ; preds = %22, %0
%15 = load i64, i64* %5
%16 = load i64, i64* %2
%17 = icmp slt i64 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i64, i64* %5
%20 = getelementptr inbounds i64, i64* %13, i64 %19
%21 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %20)
br label %22
22: ; preds = %18
%23 = load i64, i64* %5
%24 = add nsw i64 %23, 1
store i64 %24, i64* %5
br label %14
25: ; preds = %14
%26 = load i64, i64* %2
%27 = sub nsw i64 %26, 1
%28 = call i32 @quicksort(i64* %13, i32 0, i64 %27)
store i64 0, i64* %5
br label %29
29: ; preds = %33, %25
%30 = load i64, i64* %4
%31 = load i64, i64* %3
%32 = icmp sle i64 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %29
%34 = load i64, i64* %5
%35 = getelementptr inbounds i64, i64* %13, i64 %34
%36 = load i64, i64* %35
%37 = load i64, i64* %4
%38 = add nsw i64 %37, %36
store i64 %38, i64* %4
%39 = load i64, i64* %5
%40 = add nsw i64 %39, 1
store i64 %40, i64* %5
br label %29
41: ; preds = %29
%42 = load i64, i64* %5
%43 = sub nsw i64 %42, 1
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %43)
store i32 0, i32* %1
%45 = load i8*, i8** %8
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [8 x i8] c"%ld %ld\00"
@.str.1 = [4 x i8] c"%ld\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2)
%6 = load i64, i64* %1
%7 = call i8* @llvm.stacksave()
%8 = alloca i64, i64 %6
%9 = load i64, i64* %1
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %0, %11
%12 = phi i64 [ %15, %11 ], [ 0, %0 ]
%13 = getelementptr inbounds i64, i64* %8, i64 %12
%14 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %13)
%15 = add nuw nsw i64 %12, 1
%16 = load i64, i64* %1
%17 = icmp slt i64 %15, %16
br i1 %17, label %11, label %18
18: ; preds = %11, %0
%19 = phi i64 [ %9, %0 ], [ %16, %11 ]
%20 = add nsw i64 %19, -1
%21 = call i32 @quicksort(i64* %8, i32 0, i64 %20)
%22 = load i64, i64* %2
%23 = icmp slt i64 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %18, %24
%25 = phi i64 [ %29, %24 ], [ 0, %18 ]
%26 = phi i64 [ %30, %24 ], [ 0, %18 ]
%27 = getelementptr inbounds i64, i64* %8, i64 %26
%28 = load i64, i64* %27
%29 = add nsw i64 %28, %25
%30 = add nuw nsw i64 %26, 1
%31 = icmp sgt i64 %29, %22
br i1 %31, label %32, label %24
32: ; preds = %24, %18
%33 = phi i64 [ -1, %18 ], [ %26, %24 ]
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %33)
ret i32 0
}