Submission #5499407

Source Code Expand

Copy
```# 2019/05/21
# AtCoder Grand Contest 027 - A

# 1. リストを昇順ソート
# 2. 小さい方から足していく
# 2-1. xと等しくなったら、答え
# 2-2. xを超えたら、最後の1個で満足するのがいるか探索(いなければ-1)
# 2-3. nまで足しても等しくなければ、-1

# Input
n, x = map(int, input().split())
a = list(map(int, input().split()))

# 1.
a.sort()

#2.
acm = 0
ans = -1
for i in range(n):
acm += a[i]
# 2-1.
if acm == x:
ans = i + 1
break
# 2-2.
elif acm > x:
wk_acm = acm - a[i]
j = i + 1
while j < n:
if wk_acm + a[j] == x:
ans = i + 1
break
j += 1
if j >= n:
ans = i
break

# 2-3.
if i == n - 1 and x != acm:
ans = n - 1

# Output
print(ans)
```

Submission Info

Submission Time 2019-05-21 14:25:43+0900 A - Candy Distribution Again Raguon Python3 (3.4.3) 200 910 Byte AC 17 ms 3064 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 200 / 200 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt 17 ms 3064 KB
0_01.txt 17 ms 3064 KB
0_02.txt 17 ms 3064 KB
0_03.txt 17 ms 3064 KB
1_00.txt 17 ms 3064 KB
1_01.txt 17 ms 3064 KB
1_02.txt 17 ms 3060 KB
1_03.txt 17 ms 3064 KB
1_04.txt 17 ms 3060 KB
1_05.txt 17 ms 3060 KB
1_06.txt 17 ms 3064 KB
1_07.txt 17 ms 3064 KB