// File: vividvilla[P]hackerrank/src/largest-sum-m.cpp
// Function: largestSum(int, std::vector<int, std::allocator<int>>, int)
int largestSum(int k, vector<int> d, int M) {
    int best = 0;
    int N = d.size();
    vector<vector<bool> > s = vector<vector<bool> >(M, vector<bool>(k + 1, false));
    s[0][0] = true;

    for (int j = 0; j < N; j++) {
        for (int l = M - 1; l >= d[j]; l--) {
            for (int i = 1; i <= k; i++) {
                s[l][i] = s[l][i] || s[l - d[j]][i - 1];
                if (i == k && s[l][i] && l > best)
                    best = l;
            }
        }
    }

    return best;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rsi, 0x88(%rsp)
movl %edi, %eax
movq 0x88(%rsp), %rdi
movq %rdi, 0x90(%rsp)
movl %eax, 0x184(%rsp)
movq %rdi, 0x178(%rsp)
movl %edx, 0x174(%rsp)
movl $0x0, 0x170(%rsp)
callq 0x1a70
movl %eax, 0x16c(%rsp)
movslq 0x174(%rsp), %rax
movq %rax, 0x98(%rsp)
movl 0x184(%rsp), %eax
incl %eax
cltq
movq %rax, 0xa0(%rsp)
movb $0x0, 0x127(%rsp)
leaq 0x126(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x1a90
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rcx
leaq 0x128(%rsp), %rdi
leaq 0x127(%rsp), %rdx
callq 0x1aa0
jmp 0x1345
leaq 0x113(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x1b20
movq 0x98(%rsp), %rsi
movq 0x80(%rsp), %rcx
leaq 0x150(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x1b30
jmp 0x1381
leaq 0x113(%rsp), %rdi
callq 0x1bb0
leaq 0x128(%rsp), %rdi
callq 0x1bc0
leaq 0x126(%rsp), %rdi
callq 0x1bd0
xorl %eax, %eax
movl %eax, %esi
movq %rsi, 0x68(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x1be0
movq 0x68(%rsp), %rsi
movq %rax, %rdi
callq 0x1c00
movq %rdx, 0x70(%rsp)
movq %rax, 0x78(%rsp)
jmp 0x13d7
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rcx, 0x100(%rsp)
movq %rax, 0x108(%rsp)
leaq 0x100(%rsp), %rdi
movl $0x1, %esi
callq 0x1c60
movl $0x0, 0xfc(%rsp)
movl 0xfc(%rsp), %eax
cmpl 0x16c(%rsp), %eax
jge 0x174a
movl 0x174(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xf8(%rsp)
movq 0x90(%rsp), %rdi
movl 0xf8(%rsp), %eax
movl %eax, 0x64(%rsp)
movslq 0xfc(%rsp), %rsi
callq 0x1cb0
movq %rax, %rcx
movl 0x64(%rsp), %eax
cmpl (%rcx), %eax
jl 0x1732
movl $0x1, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
cmpl 0x184(%rsp), %eax
jg 0x171a
movslq 0xf8(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x1be0
movq %rax, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x1c00
movq %rdx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x14b2
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movq %rax, 0xe8(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x1cd0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x4f(%rsp)
jne 0x1570
movq 0x90(%rsp), %rdi
movl 0xf8(%rsp), %eax
movl %eax, 0x34(%rsp)
movslq 0xfc(%rsp), %rsi
callq 0x1cb0
movq %rax, %rcx
movl 0x34(%rsp), %eax
movl (%rcx), %ecx
subl %ecx, %eax
movslq %eax, %rsi
leaq 0x150(%rsp), %rdi
callq 0x1be0
movq %rax, %rdi
movl 0xf4(%rsp), %eax
decl %eax
movslq %eax, %rsi
callq 0x1c00
movq %rdx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
jmp 0x1545
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x1cd0
movb %al, 0x4f(%rsp)
movb 0x4f(%rsp), %al
movb %al, 0x1f(%rsp)
movslq 0xf8(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x1be0
movq %rax, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x1c00
movq %rdx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
jmp 0x15a9
movb 0x1f(%rsp), %al
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0xc0(%rsp)
movq %rcx, 0xc8(%rsp)
movzbl %al, %esi
andl $0x1, %esi
leaq 0xc0(%rsp), %rdi
callq 0x1c60
movl 0xf4(%rsp), %ecx
xorl %eax, %eax
cmpl 0x184(%rsp), %ecx
movb %al, 0x1e(%rsp)
jne 0x166c
movslq 0xf8(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x1be0
movq %rax, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x1c00
movq %rdx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x1621
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0xb0(%rsp)
movq %rax, 0xb8(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x1cd0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x1e(%rsp)
jne 0x1657
jmp 0x166c
movl 0xf8(%rsp), %eax
cmpl 0x170(%rsp), %eax
setg %al
movb %al, 0x1e(%rsp)
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x1679
jmp 0x1702
movl 0xf8(%rsp), %eax
movl %eax, 0x170(%rsp)
jmp 0x1702
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
jmp 0x16cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x113(%rsp), %rdi
callq 0x1bb0
leaq 0x128(%rsp), %rdi
callq 0x1bc0
leaq 0x126(%rsp), %rdi
callq 0x1bd0
jmp 0x176e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x1d00
jmp 0x176e
jmp 0x1704
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x146d
jmp 0x171c
movl 0xf8(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x1433
jmp 0x1734
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x140e
movl 0x170(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x1d00
movl 0x4(%rsp), %eax
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x118(%rsp), %rdi
callq 0x1140
nopl (%rax,%rax)