Deloitte | COGNIZANT | IBM | CAPGEMINI
import math
def is_possible(K, houses, H):
total_time = 0
for house in houses:
total_time += math.ceil(house / K)
return total_time <= H
def find_min_K(n, H, houses):
low = 1
high = max(houses)
answer = high
while low <= high:
mid = (low + high) // 2
if is_possible(mid, houses, H):
answer = mid
high = mid - 1
else:
low = mid + 1
return answer
n, H = map(int, input().split())
houses = list(map(int, input().split()))
print(find_min_K(n, H, houses))
q1
//quantiphi✅
1.3K · def max_points(points):
n = len(points)
if n == 0:
return 0
if n == 1:
return points[0]
dp = [0] * n
dp[0] = points[0]
dp[1] = max(points[0], points[1])
for i in range(2, n):
dp[i] = max(dp[i-1], points[i] + dp[i-2])
return dp[-1]
n = int(input())
points = list(map(int, input().split()))
print(max_points(points))
q2
//quantiphi ✅
1.2K · import heapq
from collections import defaultdict
def solve(n, m, k, treasures, bridges, queries):
graph = defaultdict(list)
for u, v, w in bridges:
graph[u - 1].append((v - 1, w))
results = []
for start, end in queries:
start -= 1
end -= 1
pq = [(-treasures[start], 0, start)]
visited = {}
while pq:
neg_tres, time, node = heapq.heappop(pq)
total_treasure = -neg_tres
if node == end:
results.append((total_treasure, time))
break
if node in visited and visited[node] >= total_treasure:
continue
visited[node] = total_treasure
for nei, wt in graph[node]:
if nei not in visited or visited[nei] < total_treasure + treasures[nei]:
heapq.heappush(pq, (-(total_treasure + treasures[nei]), time + wt, nei))
return results
n, m, k = map(int, input().split())
treasures = list(map(int, input().split()))
bridges = [tuple(map(int, input().split())) for _ in range(m)]
queries = [tuple(map(int, input().split())) for _ in range(k)]
result = solve(n, m, k, treasures, bridges, queries)
for treasure, time in result:
print(treasure, time)
q3
//quantiphi ✅
1.8K · def ABpair(N):
res=1
while True:
if N+res==2*(N^res):
return res
res+=1
Arithmetic bitwise pairs✅
//GalaxE solutions✅
1.2K · def solve(N,Q,commands):
slots=[0]*N
for idx in commands:
i=idx[0]
slots[i-1]^=1
return sum(slots)
Memory slot Flip✅
1.1K · def solve(N, M, grid, K):
def is_star(r, c, grid):
val = grid[r][c]
if val == 0:
return False
for dr, dc in [(-1,0), (1,0), (0,-1), (0,1)]:
nr, nc = r + dr, c + dc
if not (0 <= nr < N and 0 <= nc < M):
return False
if grid[nr][nc] != val:
return False
return True
def check_win(grid):
for r in range(1, N-1):
for c in range(1, M-1):
if is_star(r, c, grid):
return True
return False
def serialize(grid):
return tuple(tuple(row) for row in grid)
def dfs(state, turn):
grid = [list(row) for row in state]
if check_win(grid):
return (0, 1, 0) if turn == 1 else (0, 0, 1)
moves = [(r, c) for r in range(N) for c in range(M) if grid[r][c] == 0]
if not moves:
return (1, 0, 0)
total = [0, 0, 0]
for r, c in moves:
for fruit in range(1, K+1):
grid[r][c] = fruit
res = dfs(serialize(grid), 1 - turn)
for i in range(3):
total[i] += res[i]
grid[r][c] = 0 # backtrack
return tuple(total)
result = dfs(serialize(grid), 0)
print(*result)
The game of grid✅✅
1.2K · def solve(N, K, Count, A, Q, XY):
results = []
for x, y in XY:
p = A[x - 1]
c = 0
for i in range(N):
if A[i] > p:
c += Count[i]
e = (c // K) + 1
z = c + 1
if e <= y <= z + Count[x - 1] - 1:
results.append("YES")
else:
results.append("NO")
return results
Favourite Candy✅
1.2K · Foto
tocca per mostrare
tocca per mostrare
Foto
tocca per mostrare
tocca per mostrare
Foto
tocca per mostrare
tocca per mostrare
Foto
tocca per mostrare
tocca per mostrare
Foto
tocca per mostrare
tocca per mostrare
Foto
tocca per mostrare
tocca per mostrare