Problem:


Taro's Shopping

Mammy decided to give Taro his first shopping experience.
Mammy tells him to choose any two items he wants from those
listed in the shopping catalogue,
but Taro cannot decide which two, as all the items look attractive.
Thus he plans to buy the pair of two items with
the highest price sum, not exceeding the amount Mammy allows.
As getting two of the same item is boring, he wants two different items.

You are asked to help Taro select the two items.
The price list for all of the items is given.
Among pairs of two items in the list,
find the pair with the highest price sum
not exceeding the allowed amount,
and report the sum.
Taro is buying two items, not one, nor three, nor more.
Note that, two or more items in the list may be priced equally.

Input

The input consists of multiple datasets, each in the following format.

n m
a1 a2 ... an

A dataset consists of two lines.
In the first line, the number of items n and the maximum
payment allowed m are given.
n is an integer satisfying 2 &#8804; n &#8804; 1000.
m is an integer satisfying 2 &#8804; m &#8804; 2,000,000.
In the second line, prices of n items are given.
ai (1 &#8804; i &#8804; n) is the price
of the i-th item.
This value is an integer greater than or equal to 1 and
less than or equal to 1,000,000.

The end of the input is indicated by a line containing two zeros.
The sum of n's of all the datasets does not exceed 50,000.

Output

For each dataset, find the pair with the highest price sum
not exceeding the allowed amount m
and output the sum in a line.
If the price sum of every pair of items exceeds m,
output NONE instead.

Sample Input

3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0

Output for the Sample Input

40
10
99
NONE
20



Sample input:
3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0


Sample output:
40
10
99
NONE
20

Submission status: Accepted

Solution code:
maxs=[]
while(True):
    max=-1
    
    b=list(map(int,input().split()))
    n=b[0]
    m=b[1]
    if(n == 0 and m == 0):
        break
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(i+1,n):
            sum=a[i]+a[j]
            if(sum>max and sum<=m):
                max=sum
    maxs.append(max)

for i in maxs:
    if i==-1:
        print("NONE")
    else:
        print(i)

Submission status: Accepted

Solution code:
ans = []
cou = 0

while(1):
    n,m = map(int,input().split())
    if(n == 0): break
    ar = list(map(int,input().split()))
    max_ans = 0


    for i in range(n-1):
        for j in range(i+1,n):
            if(max_ans < ar[i]+ar[j] and ar[i]+ar[j] <= m):
                max_ans = ar[i] + ar[j]

    ans.append(max_ans)
    cou += 1

for i in range(cou):
    if(ans[i] == 0): print("NONE")
    else: print(ans[i])

Submission status: Accepted

Solution code:
while 1!=0:
    n, m = map(int,input().split())
    if n==0 and m==0:
        break
    lista= [int (i) for i in input().split()]
    ans = 0
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if (lista[i]+lista[j])<=m and (lista[i]+lista[j])>ans:
                ans = lista[i] + lista[j]
                
    if ans == 0:
        print('NONE')
    else:
        print(ans)

Submission status: Accepted

Solution code:
C=[0 for i in range(2)]
C=input().split()
n=(int)(C[0])
x=(int)(C[1])

B=[]
cnt=0
while n>0:

	A=[0 for i in range(n)]
	A=input().split()

	max=0

	for i in range(len(A)-1):
		for j in range(i+1, len(A)):
			if max<(int)(A[i])+(int)(A[j]) and (int)(A[i])+(int)(A[j])<=x:
				max=(int)(A[i])+(int)(A[j])
	if max>0:
		B.append(max)
	else:
		B.append("NONE")

	C=[0 for i in range(2)]
	C=input().split()
	n=(int)(C[0])
	x=(int)(C[1])

	cnt+=1

for i in range(cnt):
	print(B[i])

Submission status: Accepted

Solution code:
price = []
while 1:
    a = []
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    sum = -1
    for i in range(len(a)-1):
        for j in range(i+1,len(a)):
            if a[i] + a[j] <= m and sum <= a[i] + a[j]:
                sum = a[i] + a[j]
    if sum < 0:
        price.append(-1)
    else:
        price.append(sum)

for i in range(len(price)):
    if price[i] >= 0:
        print(price[i])
    else:
        print('NONE')

Submission status: Accepted

Solution code:
ans=[]
n,m=map(int,input().split())
while n!=0 and m!=0:
    a=[0]*n
    a=list(input().split())
    for i in range(n):
        a[i]=int(a[i])
    max=0
    for i in range(n):
        for j in range(n):
            if i<j:
                tmp=a[i]+a[j]
                if tmp>max and tmp<=m:
                    max=tmp
                else: pass
            else: pass
    ans.append(max)
    n,m=map(int,input().split())
for i in range(len(ans)):
    if ans[i]==0:
        print("NONE")
    else:
        print(ans[i])

Submission status: Accepted

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


B=[]
cnt=0
while n!=0 and m!=0:
    A=input().split()
    cnt=0
    max=0
    for i in range(n):
        A[i]=(int)(A[i])
    for i in range(n):
        for j in range(i+1,n):
            x=A[i]+A[j]
            if x>max and x<=m:
                max=x
    if max>0:
        B.append(max)
    else:
        B.append('NONE')
    cnt+=1
    n,m=input().split()
    n=(int)(n)
    m=(int)(m)

for i in range(len(B)):
    print(B[i])

Submission status: Accepted

Solution code:
A=[0 for i in range(2)]
A=input().split()
n=int(A[0])
m=int(A[1])


max=[]
k=0
while n>0 and m>0:
    B=[0 for i in range(n)]
    B=input().split()
    for i in range(n):
        B[i]=int(B[i])
    ma=0
    for i in range(n):
        for j in range(i+1,n):  
            x=0 
            x=B[i]+B[j]
            if ma<x and x<=m:
                ma=x
    max.append(ma)
    A=input().split()
    n=int(A[0])
    m=int(A[1])
    k+=1
for i in range(k):
    if max[i]>0:
        print(max[i])
    else:
        print("NONE")

Submission status: Accepted

Solution code:
A=[0 for i in range(2)]
A=input().split()
n=int(A[0])
m=int(A[1])
max=[]
k=0

while n>0 and m>0:
    B=[0 for i in range(n)]
    B=input().split()
    for i in range(n):
        B[i]=int(B[i])
    max1=0
    for i in range(n):
        for j in range(i+1,n):  
            x=0 
            x=B[i]+B[j]
            if max1<x and x<=m:
                max1=x
    max.append(max1)
    A=input().split()
    n=int(A[0])
    m=int(A[1])
    k+=1
for i in range(k):
    if max[i]>0:
        print(max[i])
    else:
        print("NONE")

Submission status: Accepted

Solution code:
A=[]
while(True):
	n,m=map(int,input().split())
	if n==0 and m==0:
		break
	#print(n,m)
	P=list(map(int,input().split()))
	#print(P)
	mark=1
	sign=1
	for i in range(n):
		for j in range(i,n):
			if i==j:
				pass
			else:
				#print(i,j)
				if m-(P[i]+P[j])>=0:
					if mark==1:
						max=P[i]+P[j]
						mark=0
						sign=0
					else:
						if P[i]+P[j]>max:
							max=P[i]+P[j]
				else:
					pass
	if sign==0:
		A.append(max)
	else:
		A.append(-1)
#print(A)
A.reverse()
for i in range(len(A)):
	tmp=A.pop()
	if tmp==-1:
		print("NONE")
	else:
		print(tmp)

Submission status: Accepted

Solution code:
n=5
m=5
z=0
sum=0
A=[]

while n!=0:
    n,m=[int(i) for i in input().split()]
    if n==0 and m==0:
        break
    val=[int(i) for i in input().split()]
    ans1=0
    mm=0
    for i in range(0,n):
        for j in range(i+1,n):
            if i==j:
                break
            ans1=val[i]+val[j]
            if ans1>mm and ans1<=m:
                mm=ans1
        ans1=0
    A.append(mm)
    z=z+1

for i in range(z):
    if A[i]==0:
        A[i]="NONE"
    print(A[i])

Submission status: Accepted

Solution code:
while True:
	n,m = map(int,input().split())
	if n == 0 and m == 0:	
		break
	a = list(map(int,input().split()))
	a.sort()
	list1 = []
	for i in range(n):
		for j in range(i + 1, n):
		 	price1 = a[i] + a[j]
		 	list1.append(price1)
	list1.sort()
	list2 = list(filter(lambda p: m >= p, list1))


	if list2:
		print(max(list2))
	else:
		print("NONE")

Submission status: Accepted

Solution code:
import sys
while(True):
    items=[]
    max=0
    n, m = map(int, input().split())
    if (n == 0 & m == 0):exit()
    items = list(map(int, input().split()))
    for i in range(n):
        for j in range(n):
            sum = items[i] + items[j]
            if (i != j and sum <= m and sum > max):
                max = sum
    if (max == 0):
        print("NONE")
    else:
        print(max)

Submission status: Accepted

Solution code:
def Price_combination():
    combination = []
    for i, x in enumerate(a):
        j = i + 1
        for y in a[j:]:
            if x + y <= m:
                combination.append(x+y)

    return combination

while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break

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

    ######## 許容範囲で金額を組み合わせる ########
    combination = Price_combination()
    ############################################

    if len(combination):
        print(max(combination))
    else:
        print("NONE")

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, raw_input().split())

    if n == 0 and m == 0:
        break

    a = map(int, raw_input().split())

    ans = -1

    for i in range(n-1):
        for j in range(i+1, n):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])

    print "NONE" if ans == -1 else ans

Submission status: Accepted

Solution code:
while True:
    t = 0
    n,m = map(int,input().split())
    if n != 0:
        a = list(map(int,input().split()))
        a.sort(reverse=True)
        for i in range(n - 1):
            k = a[i]
            for j in range(n - i - 1):
                if k + a[i+j+1] <= m:
                    if k + a[i+j+1] >= t:
                        t = k + a[i+j+1]
                    break
        if t == 0:
            print("NONE")
        else:
            print(t)
    else:
        break

Submission status: Accepted

Solution code:
while True:
    (n, m) = tuple(map(int, input().split()))
    if n == 0:
        break
    arr = list(map(int, input().split()))
    arr.sort()
    
    res = -1
    for i, e in enumerate(arr[:-1]):
        d = i + 1
        if e + arr[i + 1] > m:
            break
        u = n
        while u - d > 1:
            medi = int((u + d) / 2)
            if e + arr[medi] > m:
                u = medi
            else:
                d = medi
        res = max(res, e + arr[d])
    if res < 0:
        print("NONE")
    else:
        print(res)

Submission status: Accepted

Solution code:
while True:
    n,m=[int(i) for i in input().split()]
    if n==0:
        break 
    a = [int(i) for i in input().split()]

    ans  = -1
    for i in range(n):
        for j in range(i+1,n):
            if a[i]+a[j] <= m:
                ans =max(a[i]+a[j] ,ans)
    if ans ==-1:
        print("NONE")
    else:
        print(ans)

Submission status: Accepted

Solution code:
while True:
    S=[]
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        a=list(map(int,input().split()))
        a.sort(reverse=True)
        ans="NONE"
        for i in range(n-1):
            for j in range(i+1,n):
                s=a[i]+a[j]
                S.append(s)
        S.sort(reverse=True)
        for k in range (len(S)):
            if S[k]<=m:
                ans=S[k]
                break
            else:
                pass
        print(ans)

Submission status: Accepted

Solution code:
while True:
    n,m = map(int,input().split())
    if n==0:
      break
    a = list(map(int,input().split()))
    lst = []
    for i in range(n-1):
        for j in range(i+1, n):
            if a[i]+a[j] <= m:
                lst.append(a[i]+a[j])
    if len(lst) == 0:
        print('NONE')
    else:
        print(max(lst))

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if n==m==0:
        break
    cata=list(map(int,input().split()))
    max=0
    sum=0
    for i in range(n):
        for j in range(i+1,n):
            sum=cata[i]+cata[j]
            if sum<=m and sum>max:
                max=sum
    if max==0:
        print('NONE')
    else:
        print(max)

Submission status: Accepted

Solution code:
while True:
    n,m = map(int,input().split());
    if n == 0 and m == 0:
        break;
    B = list(map(int, input().split()));

    sum = 0;
    for i in range(0,n):
        for j in range(0,n):
            if i != j:
                if m >= B[i]+B[j]:
                    if sum <= B[i]+B[j]:
                        sum = B[i]+B[j];

    if sum == 0:
        print("NONE");
    else:
        print(sum);

Submission status: Accepted

Solution code:
while True:
	s,t = map(int,input().split())
	if s == 0 and t == 0:	
		break
	a = list(map(int,input().split()))
	a.sort()
	list1 = []
	for i in range(s):
		for j in range(i + 1, s):
		 	price1 = a[i] + a[j]
		 	list1.append(price1)
	list1.sort()
	list2 = list(filter(lambda p: t >= p, list1))


	if list2:
		print(max(list2))
	else:
		print("NONE")

Submission status: Accepted

Solution code:
while True:
    n,m=map(int, input().split())
    if n==0 and m==0:
        break
    a=list(map(int, input().split()))
    
    price=0
    for i in range(n-1):
        for j in range(i+1, n):
            if i==j:
                break
            
            if a[i]+a[j]>price and a[i]+a[j]<=m:
                price=a[i]+a[j]
                
    if price==0:
        print("NONE")
    else:
        print(price)

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    
    if n == m == 0:
        break
    
    else:
        a = list(map(int, input().split()))
        
        ans = 0
        for i in range(n):
            for j in range(1, n):
                if i != j:
                    kau = a[i] + a[j]
                    if kau <= m and kau > ans:
                        ans = kau
        
        if ans == 0:
            print('NONE')
        else:
            print(ans)

Submission status: Accepted

Solution code:
while True:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    
    b = 0
    for i in range(n):
        for j in range(i+1,n):
            if m < a[i] + a[j]:
                continue
            b = max(b,a[i] + a[j])
    if b == 0:
        print("NONE")
    else:
        print(b)

Submission status: Accepted

Solution code:
while 1:
    n,m=map(int,input().split())
    if n==m==0:
        break
    A=sorted(map(int,input().split()))
    def f():
        j=n-1
        yield 0
        for i in range(n):
            while j >=0 and m<A[i]+A[j]:
                j-=1
            if j <=i:
                break
            if j >=0:
                yield A[i]+A[j]
    print(max(f())or"NONE")

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    A=[]
    a=[]
    V=0
    if n==0 and m==0:
        break
    A=list(map(int,input().split()))
    for i in range(n-1):
        for j in range(n-i-1):
            B=0
            B=A[i]+A[i+j+1]
            if B<=m:
                a.append(B)
                V=1
    if V==0:
        print('NONE')
    else:
        print(max(a))

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    if m == 0 and n == 0:
        break
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if m >= a[i] + a[j]:
                ans = max(ans, a[i] + a[j])
    if ans == 0:
        print("NONE")
    else:
        print(ans)

Submission status: Accepted

Solution code:
while True:
   n,m = map(int, input().split())
   if n==0 and m==0:
      break
   a = list(map(int, input().split()))
   s = []
   for p in range(n):
      for q in range(n):
         if p >= q:
            pass
         else:
            if a[p] + a[q] <= m:
               s.append(a[p] + a[q])
   s.sort()
   if s == []:
      print('NONE')
   else:
      print(s[len(s)-1])

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        s=sorted(list(map(int,input().split())))
        ans=0
        for i in range(n):
            for j in reversed(range(i+1,n)):
                if s[i]+s[j]>m:
                    continue
                else:
                    ans=max(ans,s[i]+s[j])
                    break
        if ans==0:
            print("NONE")
        else:
            print(ans)

Submission status: Accepted

Solution code:
import bisect

while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = sorted(map(int, input().split()))
    index = bisect.bisect_left(a, m) - 1
    if index <= 0:
        print("NONE")
        continue
    ans = 0
    for i in range(index, 0, -1):
        for j in range(i-1, -1, -1):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])
    if ans:
        print(ans)
    else:
        print("NONE")

Submission status: Accepted

Solution code:
import sys

def main(N,M,A):
    ans = []
    for i in range(N-1):
        for j in range(i+1,N):
            if A[i]+A[j] <= M:
                ans.append(A[i]+A[j])
    return max(ans) if ans else 'NONE'

while 1:
    N,M = [int(x) for x in sys.stdin.readline().split()]
    if N==M==0:
        break
    A = [int(x) for x in sys.stdin.readline().split()]
    print(main(N,M,A))

Submission status: Accepted

Solution code:

while True:
    n,m = map(int,input().split())
    if n==m==0: break
    price = list(map(int,input().split()))
    mx = 0
    
    for i in range(n-1):
        for j in range(i+1,n):
            if mx<price[i]+price[j]<=m:
                mx = price[i]+price[j]
    
    if mx==0: print("NONE")
    else: print(mx)

Submission status: Accepted

Solution code:
while True:
    n,m = map(int,input().split())
    if n==0 and m==0:
        break
    maxz = 0
    a = input().split()
    l = list(map(int,a))
    b = 0
    
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if l[i]+l[j] <= m and  maxz < l[i]+l[j]:                    
                maxz = l[i]+l[j]
        
    if maxz ==  0:
        print("NONE")
    else:
        print(maxz)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
   n, m = map(int, input().split())   # 品物の個数、許容額
   if n + m == 0: break

   price = list(map(int, input().split()))
   #print(price)
   
   sum = 0
   max = 0
   c = 0
   for i in range(n):
      for j in range(i + 1, n):
         sum = price[i] + price[j]
         if sum <= m and sum > max:
            max = sum
            
   if max == 0:
      print("NONE")
   else:
      print(max)

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if n==0:
        break
    nmax=0
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(i+1,n):
            sum=a[i]+a[j]
            if nmax<sum<=m:
                nmax=sum
    if nmax==0:
        print("NONE")
    else :
        print(nmax)

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        exit()
    A = list(map(int, input().split()))
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if ans < A[i] + A[j] <= m:
                ans = A[i] + A[j]
    print(ans if ans != 0 else 'NONE')

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if (n,m)==(0,0):
        break
    a=list(map(int,input().split()))
    b=0
    for i in range(n):
        for j in range(i+1,n):
            if a[i]+a[j]>m:
                continue
            else:
                b=max(b,a[i]+a[j])
    if b==0:
        print("NONE")
    else:
        print(b)

Submission status: Accepted

Solution code:
while True:
    ans=[]
    n,m = map(int,input().split())
    
    if n==0 and m==0:
        break
    
    a = list(map(int,input().split()))
    
    a = sorted(a)

    b = 0
    
    for i in range(n):
        for j in range(i+1,n):
            b = a[i]+a[j]
        
            if b <= m:
                ans.append(b)
            
            else:
                break
    if len(ans)==0:
        print("NONE")
    else:
        print(max(ans))

Submission status: Accepted

Solution code:
while True:
    n, m = [int(num) for num in input().split()]
    if n == m == 0:
        break
    items = sorted([int(num) for num in input().split()])
    answer = 0
    j = n - 1
    for i in range(n):
        while j > i and items[i] + items[j] > m:
            j -= 1
        if j <= i:
            break
        answer = max(answer, items[i] + items[j])
    print(answer if answer > 0 else "NONE")

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    
    if n==0 and m==0:
        break
    
    a = [int(a) for a in input().split()]
    SUM = []
    for i in range(len(a)-1):
        a0 = a[0]
        for j in range(len(a)-1):
            sum = a0+a[j+1]
            if sum<=m:
                SUM.append(sum)
            if m<sum:
                SUM.append(0)
        a.pop(0)
    if max(SUM)==0:
        print('NONE')
    else:
        print(max(SUM))

Submission status: Accepted

Solution code:
while True :
    n, m = map(int, input().split())
    
    if n == 0 :
        break
    
    else :
        A = list(map(int, input().split()))
        s = 0
        
        As = sorted(A)
        
        for i in range(len(As) - 1) :
            for j in range(i + 1, len(As)) :
                if As[i] + As[j] <= m and As[i] + As[j] > s :
                    s = As[i] + As[j]
                    
                elif As[i] + As[j] > m :
                    break
                
        if s == 0 :
            print("NONE")
        else :
            print(s)

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().strip().split())
    if n == 0:
        break
    a = sorted(list(map(int, input().strip().split())))
    ans = 0
    po = n - 1
    for i in range(n):
        while po > i and a[i] + a[po] > m:
            po -= 1
        if po <= i:
            break
        ans = max(ans, a[i] + a[po])
    print(ans if ans > 0 else 'NONE')

Submission status: Accepted

Solution code:
while True :
    n, m = map(int, input().split())
    if n == 0 and m == 0 :
        break
    
    catalog = list(map(int, input().split()))
    
    max_p = 0
    for i in range(n-1) :
        for j in range(1, n) :
            if i != j :
                x = catalog[i] + catalog[j]
                if x <= m and x > max_p :
                    max_p = x
    if max_p == 0 :
        print("NONE")
    else :
        print(max_p)

Submission status: Accepted

Solution code:
while 1:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    Max = -9999999999
    for i in range(n):
        for j in range(n):
            if i != j:
                if m >= (a[i] + a[j]):
                    Max = max(Max,(a[i] + a[j]))
    if Max < 0:
        print("NONE")
    else:
        print(Max)

Submission status: Accepted

Solution code:
from copy import copy

def get_input():
    data_list = input().split()
    for i, v in enumerate(data_list):
        data_list[i] = int(v)
    return data_list


def remove_over_budeget(value_list, budget):
    tmp_list = copy(value_list)
    for i, v in enumerate(tmp_list):
        if v >= budget:
            del value_list[i:]
            return value_list
    return value_list

def get_max_value_list(value_list,budget):
    if value_list == []: # in preperation for all value is over budget
        return "NONE"
    max_value = 0
    for i in range(0, len(value_list)-1):
        for j in range(i+1,len(value_list)):
            # print("j", j) # debug
            # print("i", i) # debug
            combination_plan = value_list[i] + value_list[j]
            if combination_plan <= budget and combination_plan > max_value:
                max_value = combination_plan
    if max_value == 0:
        return "NONE"
    return max_value





if __name__ == "__main__":
    while True:
        item_num, budget = get_input()
        if item_num == 0:
            break
        value_list = get_input()
        value_list.sort()
        value_list = remove_over_budeget(value_list, budget)
        max_value = get_max_value_list(value_list,budget)
        # print("max_value", max_value) # debug
        print(max_value)

Submission status: Accepted

Solution code:
while 1:
    n,m = map(int,input().split())
    if n==0:break
    a = list(map(int,input().split()))
    c = []
    for i in range(n-1):
        for j in range(i+1, n):
            if a[i]+a[j] <= m:
                c.append(a[i]+a[j])
    if len(c) == 0:
        print('NONE')
    else:
        print(max(c))

Submission status: Accepted

Solution code:
from itertools import combinations
while True:
    n, p = [int(x) for x in input().split()]
    if n == 0 and p == 0:
        break
    L = [int(x) for x in input().split()]
    m = -1
    for i, j in combinations(L,2):
        if i+j <=p:
            m = max(m,i+j)
    if m > 0:
        print(m)
    else:
        print("NONE")

Submission status: Accepted

Solution code:
import os,re,sys,operator,math
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)
while 1:
    n,m=map(int,stdin.readline().rstrip().split())
    if (n,m)==(0,0):
        break
    a=[int(i) for i in stdin.readline().rstrip().split()]
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            t=a[i]+a[j]
            if t<=m:
                ans=max(ans,t)
    print(ans if ans!=0 else "NONE")

Submission status: Accepted

Solution code:
while 1:
    n, m = map(int, input().split())
    if n == 0:
        break

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

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            if m < a[i] + a[j]:
                continue

            ans = max(ans, a[i] + a[j])

    if ans == 0:
        print("NONE")
    else:
        print(ans)

Submission status: Accepted

Solution code:
ans_list = []

while True:
    n,m = map(int,input().split())
    if (n,m) == (0,0):
        break
    A = list(map(int,input().split()))
    N = len(A)
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            res = A[i] + A[j]
            if res <= m:
                ans = max(ans, res) 
    if ans == 0:
        ans = "NONE"
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())), reverse=True)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            tmp = a[i] + a[j]
            if tmp <= m:
                ans = max(ans, tmp)
    if ans == 0:
        print("NONE")
    else:
        print(ans)

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2,gcd
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

ans=[]

while 1:
    n,m=MAP()
    if n==0 and m==0:
        break
    else:
        a=LIST()
        
        lis=[sum(x) for x in list(combinations(a,2)) if sum(x)<=m]
        if not lis:
            ans.append('NONE')
        else:
            ans.append(max(lis))

for x in ans:
    print(x)

Submission status: Accepted

Solution code:
import itertools
def main(n,m):
    a = list(map(int, input().split()))
    select = list(itertools.combinations(range(n), 2))
    ans = 0
    for x,y in select:
        if ans < a[x] + a[y] <= m:
            ans = a[x] + a[y]
    if ans == 0:
        print("NONE")
    else:
        print(ans)
    return 1
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    main(n,m)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import itertools

def main():
    while True:
        n, m = map(int, input().split())
        if n == 0 : break
        ns = list(map(int, input().split()))
        ans = -1
        for p in itertools.permutations(ns, 2):
            if sum(p) <= m:
                ans = max(ans, sum(p))
        if ans == -1:
            print('NONE')
        else:
            print(ans)
main()

Submission status: Accepted

Solution code:
for v in range(1000):
  s,t = input().split()
  s = int(s)
  t = int(t)
  if s == 0:
    break
  else:
    x=[]
    A = input().split()
    B = [int(l) for l in A]
    for i in range(s):
      for j in range(s):
        if i==j:
          pass
        else:
          w=B[i]+B[j]
          if w <= t:
             x.append(w)
          else:
            pass 
    lll=len(x)
    if lll == 0:
      print("NONE")
      continue
    else:  
      mx = max(x)
      print(mx)
      continue

Submission status: Accepted

Solution code:
def solve(n, m, a):
    ans = 0
    r = n - 1
    for l in range(n):
        while r > l and a[l] + a[r] > m:
            r -= 1
        if r <= l:
            break
        ans = max(ans, a[l] + a[r])
    print(ans if ans > 0 else 'NONE')


if __name__ == '__main__':
    while True:
        n_imput, m_imput = map(int, input().split())
        if n_imput == 0:
            break
        a_imput = sorted(list(map(int, input().strip().split())))
        solve(n_imput, m_imput, a_imput)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
while True:
    n, m = map(int, input().split())
    if n == 0:
        exit()
    a = list(map(int, input().split()))
    ans = -1
    for i in range(n):
        for j in range(n):
            if i == j: continue
            s = a[i] + a[j]
            if s <= m:
                ans = max(ans, s)
    print([ans, 'NONE'][ans == -1])

Submission status: Accepted

Solution code:
while True:

    n,m = [int(x) for x in input().split()]
    if n == m == 0:
        break
    a = [int(x) for x in input().split()]

    ans = -1

    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if ans < a[i]+a[j] and a[i]+a[j] <= m:
                ans = a[i]+a[j]

    if ans == -1:
        print("NONE")
    else:
        print(ans)

Submission status: Accepted

Solution code:
import itertools

while True:
    item_n, money = [int(i) for i in input().split()]
    if item_n == money == 0:
        break
 		
    value_lst = [int(i) for i in input().split()]
 	
    max_value = -1
    can_buy = False
 	
    for i1, i2 in itertools.combinations(value_lst, 2):
        if i1 + i2 > max_value and i1 + i2 <= money:
        	max_value = i1 + i2
        	can_buy = True
        	
    if(can_buy):	
        print(max_value)
    else:
    	print('NONE')