-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
71 lines (59 loc) · 1.69 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
T = int(sys.stdin.readline().strip())
for i in range(T):
n, k = list(map(int, sys.stdin.readline().split()))
nums = list(map(int, sys.stdin.readline().split()))
pre = nums[0] - 1
count = 0
flag = False
for j in range(len(nums)):
cur = nums[j]
if flag:
break
if cur - pre - 1 + count < k:
count += cur - pre - 1
pre = nums[j]
continue
while cur - pre > 1:
count += 1
cur -= 1
if count == k:
print(pre + nums[j] - cur)
flag = True
break
pre = nums[j]
if not flag:
print(nums[-1] + k - count)
# import sys
# T = int(sys.stdin.readline().strip())
#
# for i in range(T):
# m, n, p = list(map(int, sys.stdin.readline().split()))
# a = list(map(int, sys.stdin.readline().split()))
# b = list(map(int, sys.stdin.readline().split()))
# if n < min(a) or p > sum(b):
# print(0)
# continue
# ans = 0
# for j in range(0, m):
# for k in range(j + 1, m):
# if sum(a[j:k]) <= n and sum(b[j:k]) >= p:
# ans += 1
# print(ans)
# class Solution:
# def longestConsecutive(self, nums):
# longest_streak = 0
# num_set = set(nums)
#
# for num in num_set:
# if num - 1 not in num_set:
# current_num = num
# current_streak = 1
#
# while current_num + 1 in num_set:
# current_num += 1
# current_streak += 1
#
# longest_streak = max(longest_streak, current_streak)
#
# return longest_streak