Problem:


Score : 400 points

Problem Statement

One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N.
He is interested in properties of the sequence a.

For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its beauty is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.)

Find the maximum possible value for him.

Constraints

2 \leq N \leq 1000

1 \leq a_i \leq 10^9

1 \leq K \leq N(N+1)/2

All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the answer.

Sample Input 1

4 2
2 5 2 5

Sample Output 1

12

There are 10 nonempty contiguous subsequences of a. Let us enumerate them:

contiguous subsequences starting from the first element: \{2\}, \{2, 5\}, \{2, 5, 2\}, \{2, 5, 2, 5\}

contiguous subsequences starting from the second element: \{5\}, \{5, 2\}, \{5, 2, 5\}

contiguous subsequences starting from the third element: \{2\}, \{2, 5\}

contiguous subsequences starting from the fourth element: \{5\}

(Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.)

The maximum possible bitwise AND of the beauties of two different contiguous subsequences is 12.
This can be achieved by choosing \{5, 2, 5\} (with beauty 12) and \{2, 5, 2, 5\} (with beauty 14).

Sample Input 2

8 4
9 1 8 2 7 5 6 4

Sample Output 2

32



Sample input:
4 2
2 5 2 5


Sample output:
12

Submission status: Wrong Answer

Solution code:
n,k =map(int,input().split())

aList=list(map(int,input().split()))

numList=[]
gokei=0
for i in range(n):
  gokei+=aList[i]
  numList.append(gokei)

allList=[]
allList.extend(numList)

for j in range(1,n-1):
  for i in range(j,n):
    tmp=numList[i]-numList[j-1]
    allList.append(tmp)

allList.sort()
allList.reverse()
print(allList[k-1])

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))

c,d = 0,0

for i in range(n):
    l = 0
    for j in range(n-i):
            l += a[i+j]
    if l > c:
        c,d = l,c
    elif c >= l > d:
        c,d = c,l
print(c&d)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(N):
    for j in range(i, N):
        b.append(sum(a[i:j+1]))
b.sort()
b.reverse()
print(b[K-1])

Submission status: Wrong Answer

Solution code:
(N, K) = map(int, input().split())
a = list(map(int, input().split()))

btyarr = [0 for i in range(N*(N+1)//2)]
cnt = 0
for i in range(N):
    bty = 0
    for j in range(i, N):
        bty += a[j]
        btyarr[cnt] = bty
        cnt += 1

#print(cnt)
#print(len(btyarr))

l = len(btyarr)
for i in range(28, -1, -1):
    b = 1 << i
    e = 0
    for j in range(l):
        if (btyarr[j] & b) > 0:
            tmp = btyarr[j]
            btyarr[j] = btyarr[e]
            btyarr[e] = tmp
            e += 1
    if e >= K:
        l = e
    #print(btyarr)

ans = btyarr[0]
for i in range(K):
    ans &= btyarr[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
sumlist = []

for i in range(n):
    for j in range(1,n-i+1):
        sumlist.append(sum(a[i:i+j]))

beauty = sorted(sumlist,reverse=True)[:k]
ans = False
for i in range(len(beauty)):
    if not ans:
        ans = beauty[i]
    else:
        ans = ans & beauty[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = tuple(map(int, input().split()))
nums = [int(x) for x in input().split()]

scores = []

for i in range(N):
    for j in range(i + 1, N + 1):
        scores.append(sum(nums[i:j]))

high = 0
for i in range(len(scores)):
    for j in range(i + 1, len(scores)):
        t = scores[i] & scores[j]
        if t > high:
            high = t

print(high)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
s=[0]
for i in range(n):
    s.append(a[i]+s[i])
l=[]
for i in range(1,n+1):
    for j in range(i):
        l.append(s[i]-s[j])

l.sort()
l.reverse()

g=0
while l[0]>=2**g:
    g+=1
m=0
while l[m]>2**(g-1):
    m+=1
m-=1
ans=[]
for i in range(m+1):
    x=l[i]
    for j in range(k):
        x=x&l[i+j]
    ans.append(x)
 

print(max(ans))

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))

a = [int(i) for i in input().split()]


max = 0

for right in range(K-1):
    left = int(K / (right+1)) - 1
    if right == 0:
        max = sum(a[left:])
    if max < sum(a[left:-right]):
        max = sum(a[left:-right])

print(max)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
*a,=map(int,input().split())
l=[]
for i in range(n):
    t=0
    for j in range(i,n):
        t+=a[j]
        l.append(t)
l=sorted(l)[::-1]
m=0
for i in range(len(l)-k+1):
    t=l[i]
    for j in range(i+1,i+k):
        t&=l[j]
    m=max(m,t)
print(m)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))


beauty = []
for i in range(N-1):
    for j in range(i, N):
        beauty.append(sum(A[i:j+1]))


beauty = sorted(beauty, reverse=True, key=lambda x: (len(bin(x)), bin(x)[2:].count('1')))
beauty_bin = [len(bin(b)[2:]) for b in beauty]


ans_list = []
for j in range(N-K):
    k = beauty[j:j+K]
    ans = k[0]
    for i in range(1, K):
        ans = ans & k[i]
    ans_list.append(ans)


print(max(ans_list))

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
a=list(map(int,input().split()))
s=[]
i=0
j=N
while(1):
    if(i+j<=N):
        s.append(sum(a[i:i+j]))
        i+=1
    else:
        i=0
        j-=1
    if(j==1 and i==N):    break
s.sort(reverse=True)
ans=s[0]
for i in range(K):
    ans=ans&s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from sys import stdin
from functools import reduce

def load():
    n,k = [int(x) for x in stdin.readline().split()]
    data = [int(x) for x in stdin.readline().split()]
    return (n,k,data)

def calc(n, k, data):
    subsum = [sum(data[i:j]) for i in range(len(data)) for j in range(i+1, len(data)+1)]
    subsum.sort(reverse=True)
    return reduce(lambda x,y:x&y, subsum[:k])

n, k, data = load()
print(calc(n, k, data))

Submission status: Wrong Answer

Solution code:
import heapq
n, k = map(int, input().split())
a = list(map(int, input().split()))

sums = []
for i in range(1, n + 1):
    t = 0
    for j in range(i):
        t += a[j]
    heapq.heappush(sums, -t)
    for j in range(i, n):
        t += a[j]
        t -= a[j - i]
        heapq.heappush(sums, -t)

# while sums:
#     x = heapq.heappop(sums)
#     print((-x, bin(-x)))
# exit()

def get_head_bit(n):
    b = 2**32
    while b & n == 0:
        b >>= 1
    return b


MAX = 2**32 - 1

cand = []
l = 0
mask = get_head_bit(-sums[0])
# assert mask > 0

value = MAX
while l < k:
    # try:
    head = -heapq.heappop(sums)
    # except Er:
        # pass
    # assert head >= 0

    if head & mask:
        value = value & head
        cand.append(head)
        l += 1
    else:
        for c in cand:
            # assert c > (c & (MAX ^ mask))
            heapq.heappush(sums, -(c & (MAX ^ mask)))
        cand = []
        l = 0
        if sums[0] == 0:
            value = 0
            break
        mask = get_head_bit(-sums[0])
        value = MAX

print(value)

Submission status: Wrong Answer

Solution code:
n, k =  map(int, input().split())
a = list(map(int, input().split()))
import math
m = math.ceil(n - k / 2) 
x = 0
for i in range(m):
  y = sum(a[i:(i+m)])
  x = max(x,y)
print(x)

Submission status: Wrong Answer

Solution code:
import heapq

N,K = map(int,input().split(' '))
a = list(map(int,input().split(' ')))

b = []
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sum(a[i:j]))
print(heapq.nlargest(K, b)[-1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
S=[0 for i in range(n+1)]
for i in range(1,n+1):
    S[i]=S[i-1]+a[i-1]
List=[]
for i in range(n+1):
    for j in range(i):
        List.append(S[i]-S[j])
List.sort(reverse=True)
def program(N,K,L):
    #print(N,K,L)
    M=len(L)
    b=[bin(i)[2:][::-1] for i in L]
    X=[[] for i in range(42)]
    for i in b:
        for j in range(len(i)):
            if i[j]=="1":
                X[j].append(i)
    l=42
    for i in range(41,-1,-1):
        if len(X[i])>=K:
            l=i
            break
    if l==42:
        return 0
    #print(X[l])
    R=[]
    for i in X[l]:
        if i[:-1]=="":
            R.append(0)
            continue
        R.append(int(i[:-1][::-1],2))
    R.sort(reverse=True)
    return program(len(R),K,R)+2**l
print(program(n,k,List))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [0] * N
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i-1] + A[i]
# print(B)
maxv = 0

s = []

for i in range(N):
    for j in range(i, N):
        if i == 0:
            s.append(B[j])
        else:
            s.append(B[j] - B[i-1])
# print(s)
l = sorted(s)
# print(l)
if K == 1:
    print(l[-1])
else:
    maxv = l[-1]
    for i in range(1,K):
        # print(l[-1-i])
        maxv = maxv & l[-1-i]
# print(l[-1*K])
    print(maxv)

Submission status: Wrong Answer

Solution code:
import math


def comb(n, k):
    return math.factorial(n) // (math.factorial(k) * math.factorial(n-k))

n, kk = tuple(map(int, input().split()))
sumnum = n * (n + 1) // 2
arr = tuple(map(int, input().split()))
sums = [0 for i in range(sumnum)]
hojo = [0 for i in range(n)]
point = 0

for i, e in enumerate(arr):
    for k in range(i):
        hojo[k] += e
        sums[point] = hojo[k]
        point += 1
    hojo[i] = e
    sums[point] = hojo[i]
    point += 1

maxlog = 0
maxe = max(sums)
while maxe >= 2**maxlog:
    maxlog += 1
maxlog -= 1

res = 0

for i in range(maxlog, -1, -1):
    ya = [-1 for i in range(len(sums))]
    dab = 0
    gaga = 2**i
    for e in sums:
        if e >= gaga:
            ya[dab] = e - gaga
            dab += 1

    if dab > kk:
        res += gaga
        sums = ya[:dab]
    if dab == kk:
        res += gaga
        break

print(res)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
N, K = int(N), int(K)

#array = input().split()
array_int = [int(ele) for ele in input().split()]

new_array = []
for n in range(N):
	for i in range(n, len(array_int)):
		new_array.append( array_int[n:i+1] )


#print(new_array)

tmp_max = 0
for n in range( len(new_array) ):
	x = sum(new_array[n])
	for i in range(n+2, len(new_array)):
		y = sum(new_array[i])
		tmp = x & y

		if tmp_max < tmp:
			tmp_max = tmp

print(tmp_max)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
selected = [0] * K
for i in range(N):
    a_sub = a[i:]
    for j in reversed(range(0, len(a_sub))):
        a_sub_sub = a_sub[:j + 1]
        a_sub_sub_sum = sum(a_sub_sub)
        if a_sub_sub_sum > min(selected):
            selected[0] = a_sub_sub_sum
            selected = sorted(selected)
        else:
            break
res = selected[0]
for i in range(1, K):
    res = res & selected[i]
print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
sums = []
for i in range(len(a_list)):
    for j in range(len(a_list[i:])):
        sums.append(np.sum(a_list[i:i + j + 1]))
kouho = np.sort(sums)[-k:]
ans = kouho[0]
for i in kouho[1:]:
    ans = ans & i
print(ans)

Submission status: Wrong Answer

Solution code:
(N, K) = map(int, input().split())
a = list(map(int, input().split()))

btyarr = [0 for i in range(N*(N+1)//2)]
cnt = 0
for i in range(N):
    bty = 0
    for j in range(i, N):
        bty += a[j]
        btyarr[cnt] = bty
        cnt += 1

#print(cnt)
#print(len(btyarr))

l = len(btyarr)
for i in range(8, -1, -1):
    b = 1 << i
    e = 0
    for j in range(l):
        if (btyarr[j] & b) > 0:
            tmp = btyarr[j]
            btyarr[j] = btyarr[e]
            btyarr[e] = tmp
            e += 1
    if e >= K:
        l = e
    #print(btyarr)

ans = btyarr[0]
for i in range(K):
    ans &= btyarr[i]

print(ans)

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
A = list(map(int, input().split()))
if A == [1, 1] and K==2:
    print(1)
    exit()

cumA = [0]
for a in A:
    cumA.append(a+cumA[-1])
from itertools import combinations
AA = []
for l, r in combinations(range(N+1), 2):
    AA.append(cumA[r] - cumA[l])

AA.sort(reverse=True)
ans = 0
d = len(bin(AA[0])) - 2
from bisect import bisect_right
while d>=1:
    #print(d, 1<<d, AA[K-1], AA)
    if AA[K-1] >= 1<<d:
        ans |= 1<<d
        #iaa = bisect_right(AA, 1<<d)
        #print(iaa, "iaa", 1<<d)
        #AA = AA[:iaa]
        i= 0
        while i < len(AA) and AA[i] & 1<<d:
            AA[i] ^= 1 << d
            i += 1
            if i==len(AA):
                break
        AA = AA[:i]

        d -= 1
        #print(AA)
    else:
        i=0
        #print("aaa")
        while i < len(AA) and AA[i] & 1<<d:
            AA[i] ^= 1<<d
            i += 1
        d -= 1
    AA.sort(reverse=True)
print(ans)
#print(AA)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
s = [0]
for i in range(N):
  s.append(s[i] + a[i])
# print(s)

b = []
for i1 in range(N):
  for i2 in range(i1+1, N+1):
    b.append(s[i2] - s[i1])
# print(b)

import itertools
ans = 0
for c in list(itertools.combinations(b, K)):
  tmp = 0xFFFFFFFF
  for x in c:
    tmp &= x
  if tmp > ans:
    ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
a=list(map(int, input().split()))
ls=[]
suma=sum(a)

times=0
while True:
    for i in range(times):
        ls.append(sum(a[i:i+(N-times)+1]))
    times+=1
    if len(ls)>K:
        break

ls=sorted(ls, reverse=True)
# print(ls)
tmp=ls[0]
for i in range(1,K):
    tmp=tmp&ls[i]
print(tmp)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
num_list = list(map(int, input().split()))
sum_list = []
sum_ = 0
for i in range(n):
    for j in range(i,n):
        sum_ += num_list[j]
        sum_list.append(sum_)
    sum_ = 0
sum_list.sort()
print(sum_list[len(sum_list)-k])

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    N, K = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))

    edge = 0
    if K % 2 == 0:
        edge = K // 2
    else:
        edge = K // 2 + 1

    leftA = A[:len(A)-K+edge]
    rightA = A[K-edge:]

    print(max(sum(leftA), sum(rightA)))

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
Ax = list(map(int, input().split(" ")))
"""
N, K = 8, 4
Ax = [9,1,8,2,7,5,6,4]
"""

R = []
for i in range(len(Ax)):
    for j in range(i+1, len(Ax)+1):
        #print("Ax[%d] + Ax[%d] = %d" % (i, j, sum(Ax[i:j])))
        R.append(sum(Ax[i:j]))

R.sort(reverse=True)

a = R[0]
for n in R[1:K]:
    a = a and n
print(a)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

b = []
for i in range(n):
    for j in range(i, n, 1):
        b.append(sum(a[i:j+1]))

b.sort(reverse=True)

ans = 0
for i in range(int(n*(n+1)/2)-k+1):
    tmp = b[i]
    for j in b[i:k]:
        tmp = tmp & j
    if(ans < tmp): ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    top = int(math.log(2 * k, 2)) + 1
    top = min([top, n])
    basis = sum(a[top:])
    b = [basis] * (2 ** top)
    for i in range(len(b)):
        for j in range(30):
            b[i] += a[j] if i & (1 << j) > 0 else 0
    b.sort(reverse=True)
    c = b[:]
    ret = 0
    for i in range(30, 1, -1):
        tmp = search(b, i)
        if tmp + 1 < k:
            continue
        t = 1 << i
        ret += t
        b = b[:tmp+1]
        for j in range(len(b)):
            b[j] = b[j] - (b[j] >> i << i)
        b.sort(reverse=True)

    print(ret)


def search(array, i):
    le = 0
    ri = len(array)
    while ri - le > 1:
        mi = (ri + le) // 2
        if array[mi] & 1 << i:
            le = mi
        else:
            ri = mi
    return le


main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
s = set()
for i in range(len(a)-1):
    sum_v = a[i]
    s.add(sum_v)
    for j in range(i+1, len(a)):
        sum_v += a[j]
        s.add(sum_v)
s = list(s)
for k in range(K):
    if k == 0:
        ans = s.pop(s.index(max(s)))
    else:
        ans = ans & s.pop(s.index(max(s)))
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
pml = n
cnt = 1
while True:
    if k > cnt*(cnt+1)/2:
        pml -= 1
        cnt += 1
    else:
        break
if pml == n:
    print(sum(a))
else:
    maxsum = sum(a[0:pml])
    for i in range(n- pml):
        if maxsum < sum(a[i+1:pml+i+1]):
            maxsum = sum(a[i+1:pml+i+1])
    print(maxsum)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
sumlist = []

for i in range(n):
    for j in range(1,n-i+1):
        sumlist.append(sum(a[i:i+j]))


print(sorted(sumlist,reverse=True)[k-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
sums = []
ans = 0
# 3つ以上のビット論理積をとったところで、増えることはあり得ない。2個とるときだけを考えればいい

# 全列挙して、各2の累乗よりも小さいものを二つまで、組み合わせを試す

for i in range(len(a)):
    for j in range(i, len(a)):
        sums.append(sum(a[i:j + 1]))

sums.sort()

for i in range(len(sums) - K + 1):
    li = sums[i:i+K]
    bit = li[0]
    for j in range(len(li) - 1):
        bit = bit & li[j + 1]
    ans = max(ans, bit)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    N, K = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))

    leftA = A[:len(A)-K+1]
    rightA = A[K-1:]

    print(max(sum(leftA), sum(rightA)))

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
cumA = [0]
for a in A:
    cumA.append(a+cumA[-1])
from itertools import combinations
AA = []
for l, r in combinations(range(N+1), 2):
    AA.append(cumA[r] - cumA[l])

AA.sort(reverse=True)
ans = 0
d = len(bin(AA[0])) - 2
from bisect import bisect_right
while d>=1:
    #print(d, 1<<d, AA[K-1], AA)
    if AA[K-1] >= 1<<d:
        ans |= 1<<d
        #iaa = bisect_right(AA, 1<<d)
        #print(iaa, "iaa", 1<<d)
        #AA = AA[:iaa]
        i= 0
        while i < len(AA) and AA[i] & 1<<d:
            AA[i] ^= 1 << d
            i += 1
            if i==len(AA):
                break
        AA = AA[:i]

        d -= 1
        #print(AA)
    else:
        i=0
        #print("aaa")
        while i < len(AA) and AA[i] & 1<<d:
            AA[i] ^= 1<<d
            i += 1
        d -= 1
    AA.sort(reverse=True)
print(ans)
#print(AA)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))

a = [int(i) for i in input().split()]


max = sum(a[K-1:])

for right in range(1, K):
    left = int(K / (right+1)) - 1
    if max < sum(a[left:-right]):
        max = sum(a[left:-right])

print(max)

Submission status: Wrong Answer

Solution code:
import copy
N,K = map(int,input().split(" "))
a = list(map(int,input().split(" ")))
b = [a[0]]
for i in range(N-1):
    b.append(b[i]+a[i+1])
c = copy.deepcopy(b)
for i in range(N-1):
    aa = a[i]
    for j in range(N-i-1):
        c.append(b[j+i+1]-aa)
ans = max(c)
if K == 1:
    print(ans)
else:
    c[c.index(max(c))] = 0
    for i in range(K-1):
        d = 0
        count = j
        for j in range(len(c)):
            aa = c[j] & ans
            if d < aa:
                d = aa
                count = j
        ans = d
        c[count] = 0
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n,k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = []
for i in range(n):
  for j in range(n):
    b.append(sum(a[i:j+1]))
    if b[-1] == 0:
      b.pop()
b.sort()
res = 0
for i in range(31,-1,-1):
  x = 1<<i
  ans = []
  for j in range(len(b)):
    if x&b[j]:
      ans.append(j)
  if len(ans) >= k:
    res += 1<<i
    c = []
    for l in ans:
      c.append(b[l])
    b = c
print(res)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = []
for i in range(N):
    for j in range(i+1):
        sumlist.append(sum(A[j:j+N-i]))
sumlist.sort(reverse=True)
ans = sumlist[0]
for i in range(1,K):
    ans = ans & sumlist[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

b = []
for i in range(n):
    for j in range(i, n, 1):
        b.append(sum(a[i:j+1]))

b.sort(reverse=True)

ans = 0
for i in range(int(n*(n+1)/2)-k+1):
    tmp = b[i]
    for j in b[i:k]:
        tmp = tmp & j
    print(tmp)
    if(ans < tmp): ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
buf = input()
N, K = buf.split()
N, K = int(N), int(K)

buf = input()
array = buf.split()
array_int = [int(ele) for ele in array]

new_array = []
for n in range(N):
	for i in range(n, len(array_int)):
		new_array.append( array_int[n:i+1] )


#print(new_array)

tmp_max = 0
for n in range(N):
	x = sum(new_array[n])
	for i in range(n+2, len(new_array)):
		y = sum(new_array[i])

		if tmp_max < x & y:
			#print( new_array[n] , new_array[i], x&y)
			tmp_max = x & y

print(tmp_max)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())

c = list(map(int,input().split()))

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])

l.sort()
l.reverse()
ll = l[0]

for i in range(b-1):
	ll = l[1+i] & ll

print(ll)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac

n,k=map(int,input().split())
*ac,=ac([0]+list(map(int,input().split())))

l=[]
for i in range(n+1):
  for j in range(i+1,n+1):
    l.append(ac[j]-ac[i])

l.sort(reverse=True)
print(l[k-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = []
count = 0
for i in range(N):
    for j in range(i+1):
        sumlist.append(sum(A[j:j+N-i]))
        count += 1
    if count >= K:
        sumlist.sort(reverse=True)
        break
ans = sumlist[0]
for i in range(1,K):
    ans = ans & sumlist[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    l.append(x)
l.sort()
l.reverse()
ans=l[k-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_array = [int(x) for x in input().split()]

tmp = [sum(a_array)]
for i in range(n):
    for j in range(i, n):
        sum_a = sum(a_array[j:])
        if sum_a < min(tmp) and len(tmp) == 5:
            break
        tmp.append(sum_a)

tmp = sorted(tmp)
print(tmp[-k-1])

Submission status: Wrong Answer

Solution code:
from functools import reduce

def logand(a,b):
    return a & b

def main():
    N,K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    s = []
    for l in range(N):
        for r in range(l,N):
            s.append(sum(A[l:r+1]))
    s.sort(reverse=True)
    ans = 0
    for l in range(N):
        if reduce(logand, s[l:l+K]) > ans:
            ans = reduce(logand, s[l:l+K])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    top = int(math.log(2 * k, 2)) + 1
    top = min([top, n])
    basis = sum(a[top:])
    b = [basis] * (2 ** top)
    for i in range(len(b)):
        for j in range(30):
            b[i] += a[j] if i & (1 << j) > 0 else 0
    b.sort(reverse=True)
    ret = 0
    for i in range(30, 1, -1):
        tmp = search(b, i)
        if tmp < k:
            continue
        t = 1 << i
        ret += t
        b = b[tmp:]
        for j in range(len(b)):
            b[j] = b[j] - (b[j] >> i << i)

    print(ret)


def search(array, i):
    le = 0
    ri = len(array)
    while ri - le > 1:
        mi = (ri + le) // 2
        if array[mi] & 1 << i:
            le = mi
        else:
            ri = mi
    return le


main()

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
a=list(map(int, input().split()))
ls=[]
suma=sum(a)
l=0
r=0
for i in range(N*(N+1)//2):
    tmpl=sum(a[:l])
    tmpr=sum(a[N-r-1:N])
    if tmpl>=tmpr:
        ls.append(suma-tmpr)
        r+=1
    else:
        ls.append(suma-tmpl)
        l+=1
ls=sorted(ls, reverse=True)
# print(ls)
tmp=ls[0]
for i in range(1,K):
    tmp=tmp&ls[i]
print(tmp)

Submission status: Wrong Answer

Solution code:
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = []
for i in range(n):
    for j in range(i, n):
        s.append(sum(a[i:j+1]))
for i in range(k-1):
    s.remove(max(s))
print(max(s))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [0] * N
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i-1] + A[i]

s = []

for i in range(N):
    for j in range(i, N):
        if i == 0:
            s.append(B[j])
        else:
            s.append(B[j] - B[i-1])
l = sorted(s)
print(l[-1*K])

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(sum(temp))
    if len(ls_target)>=k:
        break
    i+=1
#print (ls_target)
ls_target.sort()
print (ls_target[::-1][k-1])

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

b = []
for i in range(n):
    for j in range(i, n, 1):
        b.append(sum(a[i:j+1]))

b.sort(reverse=True)

ans = 0
for i in range(n-k):
    tmp = b[i]
    for j in b[i:k]:
        tmp = tmp & j

    if(ans < tmp): ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
l = [a[0]]
st = 0 
for i in range(1,N):
    for j in range(i):
        l.append(a[i]+l[st+j])
    l.append(a[i])
    st += i 
l.sort(reverse=True)
ans = l[0]
for i in range(1,K):
    ans &= l[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=[]
for i in range(n):
    for j in range(i+1,n):
        a=0
        a+=sum(l[i:j+1])
        s.append(a)
s.sort(reverse=True)
b=s[0]
for i in range(1,k):
    b=b&s[i]
print(b)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.append(0) #エラー対策
list=[]
for i in range(n):
    b=a[i]
    for j in range(n-i):
        list.append(b)
        b=b+a[i+j+1]
list.sort(reverse=True)
print(list[m-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [0] * N
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i-1] + A[i]
# print(B)
maxv = 0

s = []

for i in range(N):
    for j in range(i, N):
        if i == 0:
            s.append(B[j])
        else:
            s.append(B[j] - B[i-1])
l = sorted(s)
# print(l)
if K == 1:
    print(l[-1])
else:
    maxv = l[-1]
    for i in range(1,K):
        # print(l[-1-i])
        maxv = maxv & l[-1-i]

print(maxv)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
a=list(map(int, input().split()))
ls=[]
suma=sum(a)
l=0
r=0
for i in range(K):
    tmpl=sum(a[:l])
    tmpr=sum(a[N-r-1:N])
    if tmpl>=tmpr:
        ls.append(suma-tmpr)
        r+=1
    else:
        ls.append(suma-tmpl)
        l+=1
# print(ls)
tmp=ls[0]
for i in range(1,len(ls)):
    tmp=tmp&ls[i]
print(tmp)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
datalist = list(map(int,input().split()))
# print(datalist)
sumlist = []
for i in range(N):
    for k in range(i + 1,N + 1):
        sumlist.append(sum(datalist[i:k]))
# print(sumlist)
print(sorted(sumlist)[-K])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [0] * N
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i-1] + A[i]

maxv = 0

s = []

for i in range(N):
    for j in range(i, N):
        if i == 0:
            s.append(B[j])
        else:
            s.append(B[j] - B[i-1])
l = sorted(s)

if K == 1:
    print(l[-1])
else:
    maxv = l[-1]
    for i in range(1,K):
        print(l[-1-i])
        maxv = maxv & l[-1-i]

print(maxv)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))

cond = []
for i in range(len(a)):
    for j in range(i, len(a)):
        cond.append(sum(a[i:j+1]))

cond = sorted(cond)[-K:]
ans = cond[0]
for c in cond[1:]:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
*a,=map(int,input().split())
l=[]
for i in range(n):
    for j in range(i+1,n+1):
        l.append(sum(a[i:j]))
l=sorted(l)[::-1]
m=0
for i in range(len(l)-k):
    t=l[i]
    for j in range(i+1,i+k):
        t&=l[j]
    m=max(m,t)
print(m)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
beauty=[]
for i in range(n):
    for j in range(i+1,n+1):
        beauty.append(sum(a[i:j]))
beauty.sort()
beauty.reverse()
print(beauty[k-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
sums = []
ans = 0
# 3つ以上のビット論理積をとったところで、増えることはあり得ない。2個とるときだけを考えればいい

# 全列挙して、各2の累乗よりも小さいものを二つまで、組み合わせを試す

for i in range(len(a)):
    for j in range(i, len(a)):
        sums.append(sum(a[i:j + 1]))

sums.sort()

for i in range(len(sums) - 1):
    ans = max(sums[i] & sums[i+1], ans)

print(ans)