-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch.py
More file actions
41 lines (41 loc) · 1.12 KB
/
scratch.py
File metadata and controls
41 lines (41 loc) · 1.12 KB
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
for _ in range(int(input())):
k, n, l, r = list(map(int, input().split()))
li = []
sum_ = []
for i in range(k):
arr = list(map(int, input().split()))
s = sum(arr)
arr.sort()
li.append(arr)
sum_.append(s)
x = min(sum_)
y = max(sum_)
# print(x, y)
# z = sum(sum_)
mid = (x+y)//2
no_of_operations = 0
# print('mid = ', mid)
for i in range(k):
if mid == sum_[i]:
continue
if mid > sum_[i]:
t = 0
cnt = 0
for j in range(n):
t += r - li[i][j]
cnt+=1
# print("t = ", t, "j= ", j)
if t >= mid - sum_[i]:
no_of_operations = max(no_of_operations, cnt)
break
else:
t = 0
cnt = 0
for j in range(n):
t += li[i][n - j - 1] - l
cnt+=1
if t >= sum_[i] - mid:
no_of_operations = max(no_of_operations, cnt)
break
# print(no_of_operations)
print(no_of_operations)