Subject to the effect
give coins, and asked whether this coins in only two Couchu
Entry
Each test case comprising a
first line of two positive numbers
represents the total number of coins,
represents the number you want to join in the
second row
positive numbers, represents
values of coins (500)
Export
For each sample, the output can Couchu
, and the difference between the two coins of the largest of the group, and small coins ahead of a large coin. If you can not Couchu outputNo Solution
Sample input
8 15
1 2 8 7 2 4 11 15
7 14
1 8 7 2 4 11 15
Sample Output
4 11
No Solution
Resolve
Because the scope of the topic, said the value of the coin, so a direct open a big array represents the number of coins of each value of the coin sorting each query.
But this question is very pit that is to say the value of the coin in question does not exceed 500, if the array will be open only to 500 返回非0
errors, read other people's solution know, this coin's value is more than 500, the specific number is not I know, but 1000 will be open to AC
# -*- coding: utf-8 -*-
# @Time : 2019/6/7 17:22
# @Author : ValarMorghulis
# @File : 1048.py
def solve():
n, m = map(int, input().split())
money = [0 for i in range(1000)]
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x)
for i in range(n):
money[a[i]] += 1
flag = False
for i in range(n):
if a[i] != m - a[i]:
if money[m - a[i]]:
print("%d %d" % (min(a[i], m - a[i]), max(a[i], m - a[i])))
flag = True
break
elif money[a[i]] >= 2:
print("%d %d" % (a[i], a[i]))
flag = True
break
if not flag:
print("No Solution")
if __name__ == "__main__":
solve()