Skip to content

Commit 1729824

Browse files
authored
Add files via upload
Code Forces Contest Problems.
1 parent f81b1c6 commit 1729824

10 files changed

+242
-0
lines changed

Badges_CF.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Badges - Codeforces
2+
3+
b = int(input())
4+
g = int(input())
5+
n = int(input())
6+
7+
decks = []
8+
9+
for i in range(n+1):
10+
decks.append((i, n-i))
11+
12+
count = 0
13+
14+
#if 1 means boys are minimum else girls are minimum
15+
flag = 1 if min(b,g) == 1 else 0
16+
17+
18+
for idx in decks:
19+
if flag == 1:
20+
if idx[0] <= b and idx[1] <= g:
21+
#print(idx)
22+
count += 1
23+
else:
24+
if idx[1] <= g and idx[0] <= b:
25+
#print(idx)
26+
count += 1
27+
28+
print(count)
29+
30+

Block Adventure CF.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def game(arr, n, m, k):
2+
i = 0
3+
ans = True
4+
for i in range(n-1):
5+
val = max(0, arr[i+1] - k)
6+
if val < arr[i]:
7+
m += arr[i] - val
8+
elif val - arr[i] > m:
9+
ans = False
10+
break
11+
else:
12+
m -= (val - arr[i])
13+
14+
if ans:
15+
return 'YES'
16+
else:
17+
return 'NO'
18+
19+
20+
21+
22+
23+
t = int(input())
24+
while t:
25+
nmk = list(map(int, input().rstrip().split()))
26+
n = nmk[0]
27+
m = nmk[1]
28+
k = nmk[2]
29+
#heights array
30+
arr = list(map(int, input().rstrip().split()))
31+
print(game(arr, n, m, k))
32+
t = t - 1

Common Divisors-CF.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Common Divisors - Codeforces
2+
import math
3+
4+
def common_divisors(n):
5+
count = 0
6+
7+
8+
for i in range(1,round(math.sqrt(n))+1):
9+
if i != n//i:
10+
if n % i == 0:
11+
count += 2
12+
else:
13+
if n%i == 0:
14+
count += 1
15+
16+
17+
return count
18+
19+
20+
n = int(input())
21+
arr = list(map(int, input().rstrip().split()))
22+
m = min(arr)
23+
print(common_divisors(m))

Compress Words - CF.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Compress Words - Codeforces
2+
n = int(input())
3+
s_list = list(input().rstrip().split())
4+
5+

Creating a Character_CF.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Creating a Character - Codeforces
2+
3+
def create_character(s,i,e):
4+
ans = 0
5+
if s > i + e:
6+
ans = e + 1
7+
elif s + e <= i:
8+
ans = 0
9+
else:
10+
s += e
11+
ans = ((s-i)+1)//2
12+
13+
return ans
14+
15+
16+
t = int(input())
17+
while t:
18+
(s,i,e) = (map(int, input().split()))
19+
print(create_character(s,i,e))
20+
t = t - 1

From_Hero_to_Zero_CF.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#From Hero to Zero
2+
3+
4+
def hero_to_zero(n,k):
5+
count = 0
6+
while n:
7+
nex = (n//k) * k
8+
count = count + (n - nex)
9+
n = n - (n-nex)
10+
11+
while(n and n%k == 0):
12+
n = n // k
13+
count += 1
14+
15+
return count
16+
17+
18+
t = int(input())
19+
while t:
20+
nk = list(map(int, input().rstrip().split()))
21+
n = nk[0]
22+
k = nk[1]
23+
print(hero_to_zero(n,k))
24+
t = t - 1

Nauuo_and_Votes_CF.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#Nauuo and Votes - Codeforces
2+
3+
xyz = list(map(int, input().rstrip().split()))
4+
5+
up = xyz[0]
6+
down = xyz[1]
7+
tie = xyz[2]
8+
9+
10+
if tie == 0:
11+
if up > down:
12+
print('+')
13+
elif down > up:
14+
print('-')
15+
else:
16+
print('0')
17+
18+
else:
19+
if up == down and down == tie:
20+
print('?')
21+
elif up == down and tie > up:
22+
print('?')
23+
elif up > (down + tie):
24+
print('+')
25+
elif up == (down + tie):
26+
print('?')
27+
elif down > (up + tie):
28+
print('-')
29+
elif down == (up + tie):
30+
print('?')
31+
elif max(up,down) == up:
32+
if down + tie < up:
33+
print('+')
34+
elif down + tie == up:
35+
print('?')
36+
else:
37+
print('?')
38+
elif max(up,down) == down:
39+
if up + tie < down:
40+
print('-')
41+
elif up + tie == down:
42+
print('?')
43+
else:
44+
print('?')
45+
46+
47+
48+

Optimal_Currency_Exchange_CF.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Optimal Currency Exchange - Codeforces
2+
3+
n = int(input())
4+
d = int(input())
5+
e = int(input())
6+
7+
ans = n
8+
9+
i = 0
10+
while n >= (i*5*e):
11+
ans = min(ans, (n-i*5*e) % d)
12+
i += 1
13+
14+
print(ans)
15+
16+

Tale_of_Two_Lands_CF.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#Tale of Two Lands - CodeForces
2+
def TaleofTwo(a,b):
3+
count = 0
4+
#array_land = abs(a - b) + 1
5+
v_a = abs(a - b)
6+
v_b = abs(a + b)
7+
8+
#Finding the absolute values of a and b
9+
a = abs(a)
10+
b = abs(b)
11+
12+
if v_a < v_b:
13+
if (a in range(v_a, v_b + 1)) and (b in range(v_a, v_b + 1)):
14+
count = count + 1
15+
elif v_a >= v_b:
16+
if (a in range(v_b, v_a + 1)) and (b in range(v_b, v_a + 1)):
17+
count = count + 1
18+
19+
20+
return count
21+
22+
23+
24+
25+
n = int(input())
26+
27+
xyz = list(map(int, input().rstrip().split()))
28+
29+
print(TaleofTwo(arr))
30+
31+

Three_piles_of_Candies_CF.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Three piles of candies - Codeforces A
2+
3+
def three_piles(arr, n):
4+
return sum(arr)//2
5+
6+
7+
8+
9+
q = int(input())
10+
while q:
11+
arr = list(map(int, input().rstrip().split()))
12+
print(three_piles(arr, len(arr)))
13+
q = q - 1

0 commit comments

Comments
 (0)