This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int find_mth_max(int tree[], int m, int n_max) { | |
int x = 1; | |
while (2 * x < n_max) { | |
if (tree[x * 2] >= m) { | |
x *= 2; | |
} else { | |
m -= tree[x * 2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("input.txt", "r") as fi: | |
n = int(fi.readline()) | |
boys = list(map(int, fi.readline().split(" "))) | |
m = int(fi.readline()) | |
girls = list(map(int, fi.readline().split(" "))) | |
boys.sort() | |
girls.sort() | |
j = m - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("input.txt", "r") as fi: | |
k, n, p, s = map(int, fi.readline().split(" ")) | |
i = 0 | |
while True: | |
if (i + 1) * k > n or (i + 1) * k * p > s: | |
break | |
else: | |
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
angles = [] | |
n_top = 0 | |
with open("tests/01") as fi: | |
n = int(fi.readline()) | |
for _ in range(n): | |
x, y = [int(s) for s in fi.readline().split()] | |
angle = math.degrees(math.atan2(y, x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
split_table = {} | |
def get_split_sum(a, start_index, end): | |
l = end - start_index + 1 | |
if l <= 2: | |
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = [] | |
for _ in range(0, n): | |
a.append(int(input())) | |
stack = [] | |
max_taken = 0 | |
for i in range(0, n): | |
if a[i] > max_taken: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
ls = len(s) | |
stack = [s[0]] | |
i = 1 | |
while i < ls: | |
if len(stack) > 0: | |
ch = stack.pop() | |
if ch != s[i]: | |
stack.append(ch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
def get_combination_count(i): | |
global arr | |
if arr[i - 1] == -1: | |
if i <= 2: | |
arr[i - 1] = 2 | |
else: | |
arr[i - 1] = (get_combination_count(i - 2) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
long long* get_digit_count(long long n) { | |
long long* digit_count = new long long[10]; | |
long long s = n; | |
int div = 1; | |
while (s > 0) { | |
s /= 10; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_digit_count(n): | |
digit_count = [0] * 10 | |
s = n | |
div = 1 | |
while s > 0: | |
s //= 10 | |
x = n - (div - 1) | |
full_period = x // (10 * div) | |
unfull = x % (10 * div) | |
unfull_periods = unfull // div |