problem_id stringlengths 3 7 | contestId stringclasses 660
values | problem_index stringclasses 27
values | programmingLanguage stringclasses 3
values | testset stringclasses 5
values | incorrect_passedTestCount float64 0 146 | incorrect_timeConsumedMillis float64 15 4.26k | incorrect_memoryConsumedBytes float64 0 271M | incorrect_submission_id stringlengths 7 9 | incorrect_source stringlengths 10 27.7k | correct_passedTestCount float64 2 360 | correct_timeConsumedMillis int64 30 8.06k | correct_memoryConsumedBytes int64 0 475M | correct_submission_id stringlengths 7 9 | correct_source stringlengths 28 21.2k | contest_name stringclasses 664
values | contest_type stringclasses 3
values | contest_start_year int64 2.01k 2.02k | time_limit float64 0.5 15 | memory_limit float64 64 1.02k | title stringlengths 2 54 | description stringlengths 35 3.16k | input_format stringlengths 67 1.76k | output_format stringlengths 18 1.06k ⌀ | interaction_format null | note stringclasses 840
values | examples stringlengths 34 1.16k | rating int64 800 3.4k ⌀ | tags stringclasses 533
values | testset_size int64 2 360 | official_tests stringlengths 44 19.7M | official_tests_complete bool 1
class | input_mode stringclasses 1
value | generated_checker stringclasses 231
values | executable bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
169/A | 169 | A | Python 3 | TESTS | 6 | 93 | 0 | 50300743 | n, a, b = map(int, input().split())
h = list(map(int, input().split()))
temp = sorted(h)
c = max(a, b)
print(temp[c] - temp[c-1]) | 29 | 31 | 102,400 | 206252664 | def divideWork(h,a,b):
h.sort()
return h[b]-h[b-1]
n,Petya,Vasya=map(int,input().split())
h=list(map(int,input().split()))
result=divideWork(h,Petya,Vasya)
print(result) | VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) | CF | 2,012 | 2 | 256 | Chores | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger... | The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t... | Print the required number of ways to choose an integer value of x. If there are no such ways, print 0. | null | In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | [{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}] | 800 | ["sortings"] | 29 | [{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "... | false | stdio | null | true |
424/B | 424 | B | PyPy 3-64 | TESTS | 21 | 93 | 1,638,400 | 176859141 | n,s=map(int,input().split())
t=[]
for _ in range(n):
p=list(map(int,input().split()))
t.append(p[:])
l=0
high=10000
ans=-1
def check(x):
p=x**2
o=0
for x,y,k in t:
if x**2+y**2<=p:
o+=k
return o+s>=1000000
while l+0.000001<high:
mid=(l+high)/2
if check(mid):
... | 54 | 46 | 0 | 230649351 | from math import sqrt
N, t = input().split()
N, t = int(N), int(t)
rast = []
count = []
for i in range(N):
x, y, k = input().split()
x, y, k = int(x), int(y), int(k)
rast.append(sqrt(x**2 + y**2))
count.append(k)
l, r = 0, max(rast)
while r - l >= 1e-8:
m = (l + r) / 2
k = 0
for i in r... | Codeforces Round 242 (Div. 2) | CF | 2,014 | 2 | 256 | Megacity | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | null | null | [{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}] | 1,200 | ["binary search", "greedy", "implementation", "sortings"] | 54 | [{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.read().strip()
with open(submission_path, 'r') as f:
sub_line = f.read().strip()
if ref_line == '-1':
if sub_line... | true |
424/B | 424 | B | Python 3 | TESTS | 19 | 46 | 0 | 197507807 | import math
'''def truncate(number, digits) -> float:
nbDecimals = len(str(number).split('.')[1])
if nbDecimals <= digits:
return number
stepper = 10.0 ** digits
return math.trunc(stepper * number) / stepper'''
def setd(n):
return float('%.7f'%n)
def pop(l,r):
sum=0
for i in l:
... | 54 | 46 | 102,400 | 210468576 | n, s = map(int, input().split())
a = []
for _ in range(n):
x, y, k = map(int, input().split())
a.append([x ** 2 + y ** 2, k])
a.sort()
ds = 1000000 - s
dist = 0
i = 0
while i < n and ds > 0:
ds -= a[i][1]
i += 1
if i == 0: print(0)
elif ds <= 0 and i > 0: print(a[i - 1][0] ** 0.5)
else: p... | Codeforces Round 242 (Div. 2) | CF | 2,014 | 2 | 256 | Megacity | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | null | null | [{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}] | 1,200 | ["binary search", "greedy", "implementation", "sortings"] | 54 | [{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.read().strip()
with open(submission_path, 'r') as f:
sub_line = f.read().strip()
if ref_line == '-1':
if sub_line... | true |
301/C | 301 | C | PyPy 3 | TESTS | 0 | 154 | 0 | 114413189 | print("0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n>>?\n") | 23 | 124 | 0 | 19357253 | print ( """0??<>1
1??<>2
2??<>3
3??<>4
4??<>5
5??<>6
6??<>7
7??<>8
8??<>9
9??>>??0
??<>1
?0>>0?
?1>>1?
?2>>2?
?3>>3?
?4>>4?
?5>>5?
?6>>6?
?7>>7?
?8>>8?
?9>>9?
?>>??
>>?""" ) | Codeforces Round 182 (Div. 1) | CF | 2,013 | 2 | 256 | Yaroslav and Algorithm | Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of... | The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025. | Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces.
Your algorithm will be launched for each of these numbers. The answer will be considered correct if:
- Each line will a correct algorithm command (see the description in the problem ... | null | null | [{"input": "2\n10\n79", "output": "10<>11\n79<>80"}] | 2,500 | ["constructive algorithms"] | 23 | [{"input": "2\r\n10\r\n79\r\n", "output": "10<>11\r\n79<>80\r\n"}, {"input": "5\r\n9\r\n99\r\n999\r\n9999\r\n99999\r\n", "output": "0??<>1\r\n1??<>2\r\n2??<>3\r\n3??<>4\r\n4??<>5\r\n5??<>6\r\n6??<>7\r\n7??<>8\r\n8??<>9\r\n9??>>??0\r\n??<>1\r\n?0>>0?\r\n?1>>1?\r\n?2>>2?\r\n?3>>3?\r\n?4>>4?\r\n?5>>5?\r\n?6>>6?\r\n?7>>7?\... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
numbers = [int(line.strip()) for line in f]
commands = []
with open(submission_output_path) as f:
for line in f:
line = line.strip()
if '>... | true |
169/A | 169 | A | Python 3 | TESTS | 6 | 46 | 0 | 222056885 | def solve():
n, a, b = map(int, input().split())
numbers = sorted(map(int, input().split()))
print(numbers[max(a, b)] - numbers[max(a, b) - 1])
if __name__ == "__main__":
solve() | 29 | 31 | 102,400 | 217041249 | n, a, b = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
p = h[-a]
q = h[b-1]
print(p-q) | VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) | CF | 2,012 | 2 | 256 | Chores | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger... | The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t... | Print the required number of ways to choose an integer value of x. If there are no such ways, print 0. | null | In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | [{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}] | 800 | ["sortings"] | 29 | [{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "... | false | stdio | null | true |
424/B | 424 | B | PyPy 3-64 | TESTS | 29 | 93 | 102,400 | 210703673 | import math
def prsum(r):
p = [0]
for t in range(len(r)):
p.append(int(r[t])+p[-1])
return(p)
def sufsum(a):
pr = [0]
for t in range(1,len(a)+1):
pr.append(int(a[-t])+pr[-1])
return(pr)
def bl(x):
L = 0
R = x+1
while R-L > 1:
m = (L + R)//2
if m**3... | 54 | 46 | 4,505,600 | 134062531 | N, population = map(int, input().split())
locations = []
for _ in range(N):
x, y, people = map(int, input().split())
radius = (x**2 + y**2)**0.5
locations.append((radius, people))
locations.sort()
# print(locations)
MAX = -1
for radius, people in locations:
if population + people >= 10**6:
MAX =... | Codeforces Round 242 (Div. 2) | CF | 2,014 | 2 | 256 | Megacity | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | null | null | [{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}] | 1,200 | ["binary search", "greedy", "implementation", "sortings"] | 54 | [{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.read().strip()
with open(submission_path, 'r') as f:
sub_line = f.read().strip()
if ref_line == '-1':
if sub_line... | true |
754/D | 754 | D | PyPy 3 | TESTS | 4 | 93 | 409,600 | 191285274 | from collections import defaultdict
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def binary_trie():
G0, G1, cnt = [-1], [-1], [0]
return G0, G1, cnt
def insert(x, l):
j = 0
for i in range(l, -1, -1):
cnt[j] += 1
if x & pow2[i]:
if G1[j] ==... | 77 | 3,353 | 112,844,800 | 174818794 | import os, sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop
from functools import lru_cache
from itertools import accumulate
import math
import sys
from sys import stdout
# sys.setrecursionlimit(10 *... | Codeforces Round 390 (Div. 2) | CF | 2,017 | 4 | 256 | Fedor and coupons | All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.
The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with i... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose.
Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal. | In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted.
In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should c... | null | In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total.
In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example. | [{"input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2"}, {"input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2"}, {"input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4"}] | 2,100 | ["binary search", "data structures", "greedy", "sortings"] | 77 | [{"input": "4 2\r\n1 100\r\n40 70\r\n120 130\r\n125 180\r\n", "output": "31\r\n1 2 \r\n"}, {"input": "3 2\r\n1 12\r\n15 20\r\n25 30\r\n", "output": "0\r\n1 2 \r\n"}, {"input": "5 2\r\n1 10\r\n5 15\r\n14 50\r\n30 70\r\n99 100\r\n", "output": "21\r\n3 4 \r\n"}, {"input": "7 6\r\n-8 6\r\n7 9\r\n-10 -5\r\n-6 10\r\n-7 -3\r\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, k = map(int, f.readline().split())
coupons = []
for _ in range(n):
l, r = map(int, f.readline().split())
... | true |
73/C | 73 | C | Python 3 | TESTS | 5 | 154 | 307,200 | 20814485 | # Beautiful Words (DP)
# R Visser
# Python 3
# 8 Sep 2016
# Solution is O(n*k*h^2) (where h = 26)
INF = 1000000000
# Input
inp = input().split()
s = inp[0]
k = int(inp[1])
n = int(input())
# Initialise bonus
bonus = [[0 for j in range(26)] for i in range(26)]
# Input bonus
for i in range(n):
inp = input().split... | 53 | 684 | 8,089,600 | 106350494 | from math import inf
s,k= input().split()
k=int(k)
dict=[[0]*26 for i in range(26)]
for i in range(int(input())):
x=input().split()
# print(ord(x[0])-97,ord(x[1])-97)
dict[ord(x[0])-97][ord(x[1])-97]=int(x[2])
dp=[[[-inf]*26 for j in range(k+2)]for i in range(len(s))]
m=-1
for i in range(26):
if ord(s... | Codeforces Beta Round 66 | CF | 2,011 | 2 | 256 | LionAge II | Vasya plays the LionAge II. He was bored of playing with a stupid computer, so he installed this popular MMORPG, to fight with his friends. Vasya came up with the name of his character — non-empty string s, consisting of a lowercase Latin letters. However, in order not to put up a front of friends, Vasya has decided to... | The first line contains character's name s and an integer number k (0 ≤ k ≤ 100). The length of the nonempty string s does not exceed 100. The second line contains an integer number n (0 ≤ n ≤ 676) — amount of pairs of letters, giving bonus to the euphony. The next n lines contain description of these pairs «x y c», wh... | Output the only number — maximum possible euphony оf the new character's name. | null | In the first example the most euphony name will be looser. It is easy to calculate that its euphony is 36. | [{"input": "winner 4\n4\ns e 7\no s 8\nl o 13\no o 8", "output": "36"}, {"input": "abcdef 1\n5\na b -10\nb c 5\nc d 5\nd e 5\ne f 5", "output": "20"}] | 1,800 | ["dp"] | 53 | [{"input": "winner 4\r\n4\r\ns e 7\r\no s 8\r\nl o 13\r\no o 8\r\n", "output": "36"}, {"input": "abcdef 1\r\n5\r\na b -10\r\nb c 5\r\nc d 5\r\nd e 5\r\ne f 5\r\n", "output": "20"}, {"input": "akcbd 2\r\n3\r\na d 55\r\nb z 100\r\nb c 50\r\n", "output": "155"}, {"input": "adcbd 1\r\n3\r\na d 55\r\nb z 100\r\nb c 50\r\n",... | false | stdio | null | true |
58/C | 58 | C | Python 3 | TESTS | 7 | 218 | 6,041,600 | 138602811 | input()
nums = [int(i) for i in input().split()]
i = 0
ii = -1
e = 0
changed_nums = []
def get_rpart(l):
e1, e2 = 0,0
trees1, trees2 = [], []
for i in range(len(l)//2+1):
if l[i] == l[i+1]:
indlast = True
trees1.append(l[i])
for ran in range(len(nums)//2+1):
... | 40 | 280 | 14,336,000 | 207699809 | # LUOGU_RID: 111554051
from sys import stdin
from collections import defaultdict
input = stdin.readline
def get() :
return map(int,input().split())
n = int(input())
lst = [0] + list(get())
d = defaultdict(int)
res = 0
for i in range(1, n + 1) :
t = lst[i]
t -= min(i, n - i + 1)
if t >= 0... | Codeforces Beta Round 54 (Div. 2) | CF | 2,011 | 2 | 256 | Trees | On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the n-th one) should... | The first line contains integer n (1 ≤ n ≤ 105) which is the number of trees. The second line contains integers ai (1 ≤ ai ≤ 105) which are the heights of the trees. | Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful. | null | null | [{"input": "3\n2 2 2", "output": "1"}, {"input": "4\n1 2 2 1", "output": "0"}] | 1,800 | ["brute force"] | 40 | [{"input": "3\r\n2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n61452 50974 73849\r\n", "output": "2\r\n"}, {"input": "4\r\n86002 1199 86003 86002\r\n", "output": "1\r\n"}, {"input": "5\r\n92605 92606 41969 98774 92605\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 2 3... | false | stdio | null | true |
493/A | 493 | A | Python 3 | TESTS | 9 | 77 | 102,400 | 20338738 | home = input()
away = input()
fouls = int(input())
h = {}
a = {}
for _ in range(fouls):
s = input()
m,t,n,c = s.split(" ")
if t=="h":
if c=="y":
if n not in h:
h[n]=1
else:
h[n]+=1
if h[n]==2:
print(home,n,m)
... | 18 | 46 | 0 | 8957774 | home, away, n = input(), input(), int(input())
cards = {'h': {}, 'a': {}}
ans = [[] for i in range(91)]
for i in range(n):
inf = input().split()
if (not inf[2] in cards[inf[1]]):
cards[inf[1]][inf[2]] = inf[3]
if (inf[3] == 'r'):
ans[int(inf[0])] = [inf[1], inf[2]]
elif (cards[... | Codeforces Round 281 (Div. 2) | CF | 2,014 | 2 | 256 | Vasya and Football | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1 ≤ n ≤ 90) — the... | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs;
- the player's number in his team;
- the minute when he received the card.
If no player received a card, then you do not need to pr... | null | null | [{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}] | 1,300 | ["implementation"] | 18 | [{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\... | false | stdio | null | true |
492/C | 492 | C | Python 3 | TESTS | 1 | 31 | 0 | 210669066 | n , r , avg = map(int , input().split())
arr = [ list(map( int, input().split() )) for i in range(n) ]
# for i in range(n):
# x , y = map( int, input().split() )
arr = sorted(arr , key= lambda x: x[1] )
diff = avg*n
for i , j in arr: diff -= i
# print( diff)
sum = 0
for sub , ess in arr:
if diff == 0: break
... | 39 | 358 | 11,366,400 | 208069322 | import sys
from collections import defaultdict
def main() -> None:
read = sys.stdin.readline
n, r, avrg = (int(i) for i in read().split())
values: list[tuple[int, int]] = []
total_score = 0
for _ in range(n):
score, cost = (int(i) for i in read().split())
values.append((cost, scor... | Codeforces Round 280 (Div. 2) | CF | 2,014 | 1 | 256 | Vanya and Exams | Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi es... | The first line contains three integers n, r, avg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.
Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106). | In the first line print the minimum number of essays. | null | In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.
In the second sample, Vanya doesn't need to write any essays as his general point average already is above average. | [{"input": "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5", "output": "4"}, {"input": "2 5 4\n5 2\n5 2", "output": "0"}] | 1,400 | ["greedy", "sortings"] | 39 | [{"input": "5 5 4\r\n5 2\r\n4 7\r\n3 1\r\n3 2\r\n2 5\r\n", "output": "4\r\n"}, {"input": "2 5 4\r\n5 2\r\n5 2\r\n", "output": "0\r\n"}, {"input": "6 5 5\r\n1 7\r\n2 4\r\n3 5\r\n4 6\r\n5 6\r\n4 7\r\n", "output": "63\r\n"}, {"input": "1 1000000000 1000000\r\n1 1000000\r\n", "output": "999999000000\r\n"}, {"input": "10 10... | false | stdio | null | true |
547/D | 547 | D | PyPy 3 | TESTS | 12 | 826 | 48,640,000 | 98353417 | from sys import stdin, stdout
time = 0
c = 2*10**5
n = 4*10**5
d = [-1]*n
f = [-1]*n
pi = [-1]*n
def dfs(node: int, graph):
stack = []
global time
global colour
col = 0
stack.append((node, -1))
pi[node] = node
while stack:
s, ind = stack.pop()
if d[s] == -1:
... | 50 | 889 | 112,640,000 | 224152629 | from sys import stdin, stdout
from collections import defaultdict
time = 0
c = 2*10**5
n = 4*10**5+2
col = 0
finished= [0]*n
for_node = [0]*n
f_range=range
f_len=len
def dfs_euler_tour(node: int, graph):
stack = []
global colour
global col
global time
stack.append((node, -1))
while stack:
... | Codeforces Round 305 (Div. 1) | CF | 2,015 | 3 | 256 | Mike and Fish | As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish.
He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the diff... | The first line of input contains integer n (1 ≤ n ≤ 2 × 105).
The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates.
It is guaranteed that there is at least one valid answer. | Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point. | null | null | [{"input": "4\n1 1\n1 2\n2 1\n2 2", "output": "brrb"}, {"input": "3\n1 1\n1 2\n2 1", "output": "brr"}] | 2,600 | ["constructive algorithms", "dfs and similar", "graphs"] | 50 | [{"input": "4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "brrb\r\n"}, {"input": "3\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "brr\r\n"}, {"input": "3\r\n157210 22861\r\n175396 39466\r\n40933 17093\r\n", "output": "rrr\r\n"}, {"input": "5\r\n55599 84144\r\n169207 98421\r\n1909 186625\r\n31525 147710\r\n7781 82078\r\n", "out... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
n = int(f.readline())
points = []
for _ in range(n):
x, y = map(int, f.readline().split())
points.append((x, y))
... | true |
508/A | 508 | A | Python 3 | TESTS | 50 | 342 | 25,190,400 | 228696361 | # -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 22:59:31 2023
@author: zinc 2300012115
"""
n,m,k = map(int,input().split())
steps = []
#创建有空边的矩阵
matrix = [[0] * (m+2) for _ in range(n+2)]
for _ in range(k):
steps.append([int(x) for x in input().split()])
s = 0
for step in steps:
matrix[step[0]][step[1]] = 1... | 52 | 218 | 8,396,800 | 228772608 | n,m,k=map(int,input().split())
if n==1 or m==1:
for j in range(k):
hang,lie=map(int,input().split())
print(0)
else:
l1=[]
for i in range(m+2):
l1.append([False]*(n+2))
for j in range(k):
hang,lie=map(int,input().split())
l1[lie][hang]=True
if j >=3:
... | Codeforces Round 288 (Div. 2) | CF | 2,015 | 2 | 256 | Pasha and Pixels | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose an... | The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m... | If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0. | null | null | [{"input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4"}, {"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5"}, {"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0"}] | 1,100 | ["brute force"] | 52 | [{"input": "2 2 4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "4\r\n"}, {"input": "2 3 6\r\n2 3\r\n2 2\r\n1 3\r\n2 2\r\n1 2\r\n1 1\r\n", "output": "5\r\n"}, {"input": "5 3 7\r\n2 3\r\n1 2\r\n1 1\r\n4 1\r\n3 1\r\n5 3\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 3 11\r\n2 1\r\n3 1\r\n1 1\r\n1 3\r\n1 2\r\n2 3\r\n3 3\r\n3... | false | stdio | null | true |
780/D | 780 | D | Python 3 | TESTS | 5 | 77 | 7,065,600 | 36744083 | t=int(input())
a=[]
st=[]
sth=[]
flag=True
for _ in range(t):
f=True
x,y=map(str,input().split())
a.append((x,y))
if(x[0:3] in st and x[0:3] in st):
f=False
st.append(x[0:3])
if(x[0:2]+y[0] in sth and x[0:2]+y[0] in sth and ~f):
flag=False
sth.append(x[0:2]+y[0])
if(x[0:2... | 41 | 109 | 7,168,000 | 36745383 | t=int(input())
sth,st,s=[],[],[]
flag=True
for _ in range(t):
f=True
t,h=map(str,input().split())
if(t[0:3] in st):
f=False
st.append(t[0:3])
if(~f and t[0:2]+h[0] not in s):
s.append(t[0:2]+h[0])
elif(f and t[0:2]+h[0] in s and st[_] not in s):
s.append(st[_])
else:
... | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Innokenty and a Football League | Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.
Each club's full name consist of two wo... | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.
Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20. | It it is not possible to choose short names and satisfy all constraints, print a single line "NO".
Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.
If there are multiple answe... | null | In the first sample Innokenty can choose first option for both clubs.
In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.
In the third example Innokenty can choose the ... | [{"input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW", "output": "YES\nDIN\nFOO"}, {"input": "2\nDINAMO BYTECITY\nDINAMO BITECITY", "output": "NO"}, {"input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP", "output": "YES\nPLM\nPLS\nGOG"}, {"input": "3\nABC DEF\nABC EFG\nABD OOO", "output": "YES\nABD\nABE\nABO... | 1,900 | ["2-sat", "graphs", "greedy", "implementation", "shortest paths", "strings"] | 41 | [{"input": "2\r\nDINAMO BYTECITY\r\nFOOTBALL MOSCOW\r\n", "output": "YES\r\nDIN\r\nFOO\r\n"}, {"input": "2\r\nDINAMO BYTECITY\r\nDINAMO BITECITY\r\n", "output": "NO\r\n"}, {"input": "3\r\nPLAYFOOTBALL MOSCOW\r\nPLAYVOLLEYBALL SPB\r\nGOGO TECHNOCUP\r\n", "output": "YES\r\nPLM\r\nPLS\r\nGOG\r\n"}, {"input": "3\r\nABC DEF... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
clubs = []
for _ in range(n):
team, hometown = f.readline().strip().split()
clubs.append((team, hometown))
ai_list = []
bi_list = []
f... | true |
224/B | 224 | B | Python 3 | TESTS | 22 | 498 | 10,342,400 | 92956648 | import sys, os.path
from collections import*
from copy import*
import math
mod=10**9+7
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
freq=[0 for i in range(n)]
for i in range(n):
if a[... | 49 | 186 | 17,817,600 | 226278818 | from collections import Counter
MAX = 10**5 + 5
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = Counter()
unique = 0
j = 0
for i in range(n):
if cnt[a[i]] == 0:
unique += 1
cnt[a[i]] += 1
while unique == k:
... | Codeforces Round 138 (Div. 2) | CF | 2,012 | 2 | 256 | Array | You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers.
Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the gi... | The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105). | Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | null | In the first sample among numbers a1 and a2 there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | [{"input": "4 2\n1 2 2 3", "output": "1 2"}, {"input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5"}, {"input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1"}] | 1,500 | ["bitmasks", "implementation", "two pointers"] | 49 | [{"input": "4 2\r\n1 2 2 3\r\n", "output": "1 2\r\n"}, {"input": "8 3\r\n1 1 2 2 3 3 4 5\r\n", "output": "2 5\r\n"}, {"input": "7 4\r\n4 7 7 4 7 4 7\r\n", "output": "-1 -1\r\n"}, {"input": "5 1\r\n1 7 2 3 2\r\n", "output": "1 1\r\n"}, {"input": "1 2\r\n666\r\n", "output": "-1 -1\r\n"}, {"input": "1 1\r\n5\r\n", "output... | false | stdio | import sys
from collections import defaultdict
def count_at_most_k(a, k):
n = len(a)
count = defaultdict(int)
unique = 0
left = 0
res = 0
for right in range(n):
x = a[right]
if count[x] == 0:
unique += 1
count[x] += 1
while unique > k:
y =... | true |
224/B | 224 | B | PyPy 3 | TESTS | 22 | 342 | 10,752,000 | 49868946 | def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
import sys
sys.setrecursionlimit... | 49 | 186 | 18,534,400 | 191634793 | from math import ceil
from collections import defaultdict, deque
n, k = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
def solve(A, n, k):
S = set()
d = 0
for i in range(n):
if A[i] not in S:
d += 1
S.add(A[i])
if d == k:
... | Codeforces Round 138 (Div. 2) | CF | 2,012 | 2 | 256 | Array | You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers.
Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the gi... | The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105). | Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | null | In the first sample among numbers a1 and a2 there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | [{"input": "4 2\n1 2 2 3", "output": "1 2"}, {"input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5"}, {"input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1"}] | 1,500 | ["bitmasks", "implementation", "two pointers"] | 49 | [{"input": "4 2\r\n1 2 2 3\r\n", "output": "1 2\r\n"}, {"input": "8 3\r\n1 1 2 2 3 3 4 5\r\n", "output": "2 5\r\n"}, {"input": "7 4\r\n4 7 7 4 7 4 7\r\n", "output": "-1 -1\r\n"}, {"input": "5 1\r\n1 7 2 3 2\r\n", "output": "1 1\r\n"}, {"input": "1 2\r\n666\r\n", "output": "-1 -1\r\n"}, {"input": "1 1\r\n5\r\n", "output... | false | stdio | import sys
from collections import defaultdict
def count_at_most_k(a, k):
n = len(a)
count = defaultdict(int)
unique = 0
left = 0
res = 0
for right in range(n):
x = a[right]
if count[x] == 0:
unique += 1
count[x] += 1
while unique > k:
y =... | true |
224/B | 224 | B | PyPy 3 | TESTS | 22 | 248 | 12,697,600 | 223602534 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = 1
r = n
old_e = a[0]
count = 1
no_duplicate = 0
distinc_a = {e: 0 for e in a}
if k == 1:
print(1, 1)
elif len(distinc_a) < k:
print(-1, -1)
else:
for index, e in enumerate(a, start=1):
if index == 1:
continue... | 49 | 216 | 12,902,400 | 207324984 | n, k = map(int, input().replace("\n", "").split(" "))
arr = list(map(int, input().replace("\n", "").split(" ")))
l, r = 1, 1
s = dict()
c = 0
for i in range(n):
# if arr[i] in s.keys():
# s[arr[i]] = i
# else:
# s.add(arr[i])
s[arr[i]] = i
if len(s) == k:
r = max(s.values())
... | Codeforces Round 138 (Div. 2) | CF | 2,012 | 2 | 256 | Array | You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers.
Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the gi... | The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105). | Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | null | In the first sample among numbers a1 and a2 there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | [{"input": "4 2\n1 2 2 3", "output": "1 2"}, {"input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5"}, {"input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1"}] | 1,500 | ["bitmasks", "implementation", "two pointers"] | 49 | [{"input": "4 2\r\n1 2 2 3\r\n", "output": "1 2\r\n"}, {"input": "8 3\r\n1 1 2 2 3 3 4 5\r\n", "output": "2 5\r\n"}, {"input": "7 4\r\n4 7 7 4 7 4 7\r\n", "output": "-1 -1\r\n"}, {"input": "5 1\r\n1 7 2 3 2\r\n", "output": "1 1\r\n"}, {"input": "1 2\r\n666\r\n", "output": "-1 -1\r\n"}, {"input": "1 1\r\n5\r\n", "output... | false | stdio | import sys
from collections import defaultdict
def count_at_most_k(a, k):
n = len(a)
count = defaultdict(int)
unique = 0
left = 0
res = 0
for right in range(n):
x = a[right]
if count[x] == 0:
unique += 1
count[x] += 1
while unique > k:
y =... | true |
554/B | 554 | B | Python 3 | PRETESTS | 4 | 46 | 0 | 11748194 | __author__ = 'Adam'
import sys
n = sys.stdin.readline().replace('\n', '')
n = int(n)
x = []
for i in range(n):
x.append(sys.stdin.readline().replace('\n', ''))
#print(x)
x1 = []
for i in x:
xxx = []
for j in i:
xxx.append(int(j))
x1.append(xxx)
#print(x1)
count1 = sum([1 for i in x1 if sum(... | 36 | 46 | 0 | 166035312 | import sys
input = sys.stdin.readline
n = int(input())
d = {}
for i in range(n):
s = input()
if(s not in d):
d[s] = 0
d[s] += 1
ans = 0
for i in d:
ans = max(ans, d[i])
print(ans) | Codeforces Round 309 (Div. 2) | CF | 2,015 | 2 | 256 | Ohana Cleans Up | Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it ... | The first line of input will be a single integer n (1 ≤ n ≤ 100).
The next n lines will describe the state of the room. The i-th line will contain a binary string with n characters denoting the state of the i-th row of the room. The j-th character on this line is '1' if the j-th square in the i-th row is clean, and '0... | The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. | null | In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything. | [{"input": "4\n0101\n1000\n1111\n0101", "output": "2"}, {"input": "3\n111\n111\n111", "output": "3"}] | 1,200 | ["brute force", "greedy", "strings"] | 36 | [{"input": "4\r\n0101\r\n1000\r\n1111\r\n0101\r\n", "output": "2\r\n"}, {"input": "3\r\n111\r\n111\r\n111\r\n", "output": "3\r\n"}, {"input": "10\r\n0100000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n0000000000\r\n", "output": "9\r\n"}, {"input"... | false | stdio | null | true |
445/A | 445 | A | Python 3 | TESTS | 12 | 62 | 0 | 203647933 | row, col = map(int, input().split())
# temp = [[s] for s in [*open(0)][1:]]
temp = [input() for _ in range(row)]
ans = [['-'] * col for _ in range(row)]
flag = 0
for i in range(row):
for j in range(col):
flag += 1
flag %= 2
if temp[i][j] != '-':
if flag:
ans[i][j]... | 37 | 31 | 0 | 155076101 | n,m=list(map(int,input().split()))
for i in range(n):
myString=list(input())
for j in range(m):
if myString[j]==".":
if ((i+j)%2==0):
myString[j]="B"
else:
myString[j]="W"
print("".join(myString)) | Codeforces Round 254 (Div. 2) | CF | 2,014 | 1 | 256 | DZY Loves Chessboard | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa... | The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).
Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad. | Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guara... | null | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | [{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}] | 1,200 | ["dfs and similar", "implementation"] | 37 | [{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\r\n",... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.readlines()
n, m = map(int, lines[0].split())
input_grid = [list(line.strip()) for line in lines[1:n+1]]
with open(submission_path) as f:
... | true |
447/B | 447 | B | PyPy 3-64 | TESTS | 10 | 171 | 11,571,200 | 163603434 | import string
s = input()
k = int(input())
w = [int(x) for x in input().split(" ")]
alpha = {}
max_w_index = 0
best_letter = ''
for i in range(len(w)):
alpha[string.ascii_lowercase[i]] = w[i]
if w[i] > w[max_w_index]:
max_w_index = i
best_letter = string.ascii_lowercase[i]
new_string = s + str(... | 24 | 46 | 0 | 139922483 | # cook your dish here
s = input()
k = int(input())
a1 = list(map(int, input().split()))
count = 0
arr = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
# list(arr)
# print(arr)
for i in range(len(s)):
# print(s[i],a[i])
b = arr.index(s[i])
# print(b)... | Codeforces Round #FF (Div. 2) | CF | 2,014 | 1 | 256 | DZY Loves Strings | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
$$f(s) = \sum_{i=1}^{|s|} (w_{s_i} \cdot i).$$
Now DZY has a str... | The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | null | In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | [{"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41"}] | 1,000 | ["greedy", "implementation"] | 24 | [{"input": "abc\r\n3\r\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "41\r\n"}, {"input": "mmzhr\r\n3\r\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453\r\n", "output": "29978\r\n"}, {"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\r... | false | stdio | null | true |
279/B | 279 | B | PyPy 3-64 | TESTS | 29 | 186 | 13,619,200 | 189922855 | n, t = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) <= t:
print(n)
elif min(a) > t:
print(0)
else:
if a[0] <= t:
l, r = 0, 1
s = a[0]
out = 1
for i in range(1, n):
while r < n and s + a[r] <= t:
s += a[r]
... | 38 | 154 | 9,625,600 | 186048046 | n , t = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
leftIdx = 0 # inclusive
rightIdx = 0 # exclusive
maxBooks = 0
nbooks = 0
budget = 0
# first sliding window
while rightIdx<n:
if budget+a[rightIdx]<=t:
budget += a[rightIdx]
nbooks += 1
rightIdx+=1
e... | Codeforces Round 171 (Div. 2) | CF | 2,013 | 2 | 256 | Books | When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the ... | The first line contains two integers n and t (1 ≤ n ≤ 105; 1 ≤ t ≤ 109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 104), where number ai shows the number of minutes that the boy needs to read the i-th book. | Print a single integer — the maximum number of books Valera can read. | null | null | [{"input": "4 5\n3 1 2 1", "output": "3"}, {"input": "3 3\n2 2 3", "output": "1"}] | 1,400 | ["binary search", "brute force", "implementation", "two pointers"] | 38 | [{"input": "4 5\r\n3 1 2 1\r\n", "output": "3\r\n"}, {"input": "3 3\r\n2 2 3\r\n", "output": "1\r\n"}, {"input": "1 3\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n4\r\n", "output": "1\r\n"}, {"input": "2 10\r\n6 4\r\n", "output": "2\r\n"}, {"input": "6 10\r\n2 3 4 2 1 1\r\n", "output": "4\r\n"}, {"input": "7 13\r\... | false | stdio | null | true |
15/A | 15 | A | Python 3 | TESTS | 7 | 62 | 0 | 218096002 | # LUOGU_RID: 120011834
n, t = map(int, input().split())
house = []
for i in range(n):
x, a = map(int, input().split())
house.append((x - a / 2, x + a / 2))
lens = []
for i in range(n - 1):
lens.append(house[i + 1][0] - house[i][1])
n = 2
for i in lens:
if i == t:
n += 1
elif i > t:
n... | 35 | 92 | 0 | 145819746 | n, t = [float(it) for it in input().split(' ')]
n =int(n)
cont = list()
for i in range(n):
hCenter, hLen = [float(it) for it in input().split(' ')]
cont.append([hCenter - hLen / 2, hCenter + hLen / 2])
cont.sort(key=lambda item: item[0])
ans = 2
for i in range(n - 1):
gap = cont[i + 1][0] - cont[i][1]
... | Codeforces Beta Round 15 | ICPC | 2,010 | 2 | 64 | Cottage Village | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Pe... | The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). | Output the amount of possible positions of the new house. | null | It is possible for the x-coordinate of the new house to have non-integer value. | [{"input": "2 2\n0 4\n6 2", "output": "4"}, {"input": "2 2\n0 4\n5 2", "output": "3"}, {"input": "2 3\n0 4\n5 2", "output": "2"}] | 1,200 | ["implementation", "sortings"] | 35 | [{"input": "2 2\r\n0 4\r\n6 2\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 4\r\n5 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n0 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n1 1\r\n", "output": "2\r\n"}, {"i... | false | stdio | null | true |
282/C | 282 | C | Python 3 | TESTS | 0 | 60 | 0 | 226850960 | # Read input strings a and b
a = input().strip()
b = input().strip()
# Check if the lengths of a and b are the same
if len(a) != len(b):
print("NO")
else:
# Check if a and b have different values at the same position
if any(a[i] != b[i] for i in range(len(a))):
print("NO")
else:
# Check... | 107 | 466 | 10,035,200 | 18496354 | import random
def er():
print("NO")
exit(0)
def ok():
print("YES")
exit(0)
def main():
a = input()
b = input()
n = len(a)
m = len(b)
if n != m:
er()
if n == 1:
if a == b:
ok()
else:
er()
x = 0
y = 0
for i in a:
... | Codeforces Round 173 (Div. 2) | CF | 2,013 | 2 | 256 | XOR and OR | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ... | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.
It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | null | null | [{"input": "11\n10", "output": "YES"}, {"input": "1\n01", "output": "NO"}, {"input": "000\n101", "output": "NO"}] | 1,500 | ["constructive algorithms", "implementation", "math"] | 107 | [{"input": "11\r\n10\r\n", "output": "YES\r\n"}, {"input": "1\r\n01\r\n", "output": "NO\r\n"}, {"input": "000\r\n101\r\n", "output": "NO\r\n"}, {"input": "1101\r\n1111\r\n", "output": "YES\r\n"}, {"input": "11000001\r\n00000001\r\n", "output": "YES\r\n"}, {"input": "01\r\n10\r\n", "output": "YES\r\n"}, {"input": "0000\... | false | stdio | null | true |
715/B | 715 | B | Python 3 | TESTS | 4 | 186 | 819,200 | 40085044 | import math
import queue
n, m, L, s, t = map(int, input().split())
INF = 1e18
adj = [[] for i in range(n)]
edges = []
def dijkstra(adj, s):
n = len(adj)
dist = [INF] * n
dist[s] = 0
pq = queue.PriorityQueue()
pq.put((0, s))
while pq.qsize():
du, u = pq.get()
if du != ... | 179 | 421 | 20,787,200 | 206713628 | import bisect
import decimal
import heapq
import sys
from types import GeneratorType
from math import inf
from functools import cmp_to_key
from collections import defaultdict, Counter, deque
import math
from functools import lru_cache
from heapq import nlargest
from functools import reduce
import random
from itertools ... | Codeforces Round 372 (Div. 1) | CF | 2,016 | 4 | 256 | Complete The Graph | ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg... | The first line contains five integers n, m, L, s, t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 10 000, 1 ≤ L ≤ 109, 0 ≤ s, t ≤ n - 1, s ≠ t) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, m lines describing the edges of the graph follow. i-th of th... | Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next m lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. i-th of them should contain three integers ui, vi ... | null | Here's how the graph in the first sample case looks like :
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456... | [{"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"}, {"input": "2 1 123456789 0 1\n0 1 0", "output": "YES\n0 1 123456789"}, {"input": "2 1 999999999 1 0\n0 1 1000000000", "output": "NO"}] | 2,300 | ["binary search", "constructive algorithms", "graphs", "shortest paths"] | 179 | [{"input": "5 5 13 0 4\r\n0 1 5\r\n2 1 2\r\n3 2 3\r\n1 4 0\r\n4 3 4\r\n", "output": "YES\r\n0 1 5\r\n2 1 2\r\n3 2 3\r\n1 4 8\r\n4 3 4\r\n"}, {"input": "2 1 123456789 0 1\r\n0 1 0\r\n", "output": "YES\r\n0 1 123456789\r\n"}, {"input": "2 1 999999999 1 0\r\n0 1 1000000000\r\n", "output": "NO\r\n"}, {"input": "4 5 10 1 2\... | false | stdio | import sys
from heapq import heappush, heappop
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m, L, s, t = map(int, f.readline().split())
original_edges = {}
for _ in range(m):
... | true |
37/A | 37 | A | Python 3 | TESTS | 57 | 218 | 0 | 84382264 | n=int(input())
s=input().split()
a=[]
for i in s:
a.append(i)
a.sort()
k=1
v=0
b=1
for i in range(len(a)-1):
z=a[i]
if z==a[i+1]:
k+=1
else:
k=1
b+=1
if k>v:
v=k
print(v,b) | 61 | 92 | 0 | 4569650 | #!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
n, = readln()
cnt = {}
for l in readln():
cnt[l] = cnt.get(l, 0) + 1
print(max(cnt.values()), len(cnt)) | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
37/B | 37 | B | PyPy 3-64 | TESTS | 1 | 61 | 0 | 202914845 | N, hp, reg = map(int, input().split())
pw = [0] * N;
dmg = [0] * N;
for i in range(N) :
pw[i], dmg[i] = map(int, input().split())
use = [-1] * N
tot = 0
cur = hp
time = 0
ans = []
while True :
cur = min(cur - tot + reg, hp)
if cur <= 0 :
break
i = -1
for j in range(N) :
if cur * ... | 95 | 93 | 2,048,000 | 217863337 | n, max_val, reg = map(int, input().split())
pow_vals = [0] * (n + 1)
dmg_vals = [0] * (n + 1)
for i in range(1, n + 1):
pow_vals[i], dmg_vals[i] = map(int, input().split())
used = [False] * (n + 1)
cur = max_val
tot = 0
ans = -1
m = 0
a = [0] * (n + 1)
b = [0] * (n + 1)
for it in range(10001):
cur = cur - tot +... | Codeforces Beta Round 37 | CF | 2,010 | 1 | 256 | Computer Game | Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.
While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:
1) The boss has t... | The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000). | In case Petya can’t complete this level, output in the single line NO.
Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the... | null | null | [{"input": "2 10 3\n100 3\n99 1", "output": "NO"}, {"input": "2 100 10\n100 11\n90 9", "output": "YES\n19 2\n0 1\n10 2"}] | 1,800 | ["greedy", "implementation"] | 95 | [{"input": "2 10 3\r\n100 3\r\n99 1\r\n", "output": "NO\r\n"}, {"input": "2 100 10\r\n100 11\r\n90 9\r\n", "output": "YES\r\n19 2\r\n0 1\r\n10 2\r\n"}, {"input": "10 100 5\r\n61 3\r\n55 2\r\n12 6\r\n39 5\r\n21 10\r\n39 7\r\n16 1\r\n10 1\r\n70 5\r\n100 7\r\n", "output": "YES\r\n21 6\r\n0 10\r\n15 9\r\n17 1\r\n18 2\r\n19... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 190671696 | l=[int(item)for item in input().split()]
s=l[1]
c=0
for i in range(0,l[0]):
a,b=((item)for item in input().split())
if a=="+":
s+=int(b)
else:
if s>int(b):
s-=int(b)
else:
c+=1
print(s,c) | 34 | 31 | 0 | 145988723 | n, x = map(int, input().split())
count = 0
for i in range(n):
Character, num = map(str, input().split())
if Character == '-':
if int(num) <= x:
x = x - int(num)
else:
count = count + 1
else:
x = x + int(num)
print(x, "", count) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 30 | 0 | 183524063 | l = []
s = input()
l = s.split()
n = int(l[0])
np =int(l[1])
j = []
for i in range(0,n,1):
j.append(input())
j[i] = (j[i]).split()
nk = 0
for i in range(0,n,1):
if j[i][0] == '+' :
np += int(j[i][1])
elif j[i][0] == '-' and np - int(j[i][1]) < 0:
nk += 1
elif j[i][0] == '-' and np - ... | 34 | 31 | 0 | 146064285 | n,x = map(int,input().split())
cnt =0
for __ in range(n):
a,b = map(str,input().split())
b = int(b)
if a =="+":
x += b
elif a=="-":
if x>=b:
x-=b
else:
cnt += 1
print(x,cnt) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 210822135 | # -*- coding: utf-8 -*-
"""
Created on Sat Jun 24 04:28:45 2023
@author: RadmediX
"""
(n,totalIce) = tuple(map(int,input().split()))
sad = 0
for i in range(n):
s = list(map(str,input().split()))
if s[0] == '+':
totalIce += int(s[1])
elif int(s[1]) < totalIce:
totalIce -= int(s[1])
... | 34 | 31 | 0 | 155922354 | n = input().split(" ")
now = int(n[1])
child = 0
for i in range(int(n[0])):
order = input().split(" ")
if order[0] == '-' and int(order[1]) <= now:
now -= int(order[1])
elif order[0] == '+':
now += int(order[1])
else:
child += 1
continue
print(now, " ", child) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
445/A | 445 | A | Python 3 | TESTS | 18 | 62 | 409,600 | 104836895 | n,m=map(int,input().split())
s="".join(input() for __ in range(n))
if m%2==0:
a=list(("BW"*int(m/2)+"WB"*int(m/2))*int(n/2) if n%2==0 else ("BW"*int(m/2)+"WB"*int(m/2))*int(n/2)+"BW"*int(m/2))
for j in range(len(s)):
if s[j]=="-":
a[j]="-"
for k in range(0,len(a),m):
print(*a[k:... | 37 | 46 | 0 | 131931769 | # -*- coding: utf-8 -*-
"""
Created on Thu Oct 14 19:09:55 2021
@author: DELL
"""
n,m = map(int,input().split())
c = ['B','W']
for i in range(n):
line = input()
color = ''
for j in range(m):
if line[j] == '-':
color += '-'
else:
color += c[(i+j)%2]
print(color)
... | Codeforces Round 254 (Div. 2) | CF | 2,014 | 1 | 256 | DZY Loves Chessboard | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa... | The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).
Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad. | Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guara... | null | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | [{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}] | 1,200 | ["dfs and similar", "implementation"] | 37 | [{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\r\n",... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.readlines()
n, m = map(int, lines[0].split())
input_grid = [list(line.strip()) for line in lines[1:n+1]]
with open(submission_path) as f:
... | true |
37/A | 37 | A | Python 3 | TESTS | 57 | 124 | 307,200 | 115062556 | n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
m=0
c=1
# print(l)
for i in range(n-1):
if l[i]==l[i+1]:
c+=1
else:
c=1
m=max(m,c)
# print(c)
print(m,len(set(l))) | 61 | 92 | 0 | 132031998 | n = int(input())
a = list(map(int,input().split()))
a.sort()
b = 1
h = 1
hmax = 1
for i in range(n-1):
if a[i] != a[i+1]:
b+=1
h = 1
else:
h+=1
if h > hmax:
hmax = h
print(hmax,b) | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
37/A | 37 | A | PyPy 3-64 | TESTS | 57 | 124 | 0 | 210636866 | a=int(input())
k=[int(x) for x in input().split()]
k.sort()
#k.append(0)
mct=0
ccount=1
numtower=1
for x in range(0,a-1):
if k[x]==k[x+1]:
ccount+=1
mct = max(mct, ccount)
else:
mct=max(mct,ccount)
ccount=1
numtower+=1
print(mct, numtower) | 61 | 92 | 0 | 132096725 | #n, m, k =map(int,input().split())
n = int(input())
mass = list(map(int,input().split()))
mass.sort()
max = 1
i = 0
k = 1
while(i<len(mass)-1):
size = 1
while(mass[i]==mass[i+1]):
size += 1
if(max<size):
max = size
i +=1
if(i >= len(mass)-1):
k -= 1
... | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
546/B | 546 | B | Python 3 | TESTS | 4 | 31 | 0 | 229848151 | n = int(input())
a = list(map(int, input().split()))
res=0
for i in range(n-1):
for j in range(i+1,n):
if a[i]==a[j]:
a[j]+=1
res+=1
print(res) | 49 | 62 | 307,200 | 11208515 | import math
import sys
n=int(input())
c=list(map(int,input().split()))
c.sort()
ans=0
for i in range(1,n):
if c[i]<=c[i-1]:
ans += c[i-1]+1-c[i]
c[i] = c[i-1]+1
print(ans) | Codeforces Round 304 (Div. 2) | CF | 2,015 | 3 | 256 | Soldier and Badges | Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.
For every pair of soldiers one of them should get a badge with strictly higher factor than the second... | First line of input consists of one integer n (1 ≤ n ≤ 3000).
Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge. | Output single integer — minimum amount of coins the colonel has to pay. | null | In first sample test we can increase factor of first badge by 1.
In second sample test we can increase factors of the second and the third badge by 1. | [{"input": "4\n1 3 1 4", "output": "1"}, {"input": "5\n1 2 3 2 5", "output": "2"}] | 1,200 | ["brute force", "greedy", "implementation", "sortings"] | 49 | [{"input": "4\r\n1 3 1 4\r\n", "output": "1"}, {"input": "5\r\n1 2 3 2 5\r\n", "output": "2"}, {"input": "5\r\n1 5 3 2 4\r\n", "output": "0"}, {"input": "10\r\n1 1 2 3 4 5 6 7 8 9\r\n", "output": "9"}, {"input": "11\r\n9 2 10 3 1 5 7 1 4 8 6\r\n", "output": "10"}, {"input": "4\r\n4 3 2 2\r\n", "output": "3"}, {"input":... | false | stdio | null | true |
37/A | 37 | A | Python 3 | TESTS | 57 | 248 | 409,600 | 42798543 | n = int(input())
a = list(map(int, input().split()))
a.sort()
count = maxi = 0
towers = 0
for i in range(n):
count += 1
if (i != 0 and (i == n - 1 or a[i] != a[i + 1])) or (i == 0 and n > 1 and a[i] != a[i + 1]):
maxi = max(count, maxi)
towers += 1
count = 0
print(maxi, towers) | 61 | 92 | 0 | 139122064 | n = int(input())
a = [int(i) for i in input().split()]
col = len(set(a))
b = []
for i in list(set(a)):
b.append(a.count(i))
print(max(b), col) | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
37/A | 37 | A | Python 3 | TESTS | 57 | 248 | 409,600 | 68856814 | h=int(input())
a=list(map(int,input().split()))
s=0
for i in range(h-1):
if a[i] in a[i+1:len(a)]:
h-=1
if s<a.count(a[i]):
s=a.count(a[i])
print(s,h) | 61 | 92 | 0 | 143800387 | n = int(input())
lst = list(map(int, input().split()))
DIC = {}
for i in lst:
DIC[i] = DIC.get(i, 0) + 1
mx = 0
for i in DIC:
if DIC[i] > mx:
mx = DIC[i]
print(mx, len(DIC)) | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
37/A | 37 | A | Python 3 | TESTS | 57 | 248 | 0 | 50762457 | n=int(input())
h=dict()
s=input()
max=0
l=s.split()
h[l[0]]=1
for i in range(1,n):
a=l[i]
if (a not in h):
h[a]=1
else:
h[a]+=1
max=h[l[0]]
for i in h.values():
if (i>max):
max=i
print(max," ",len(h)) | 61 | 92 | 0 | 143954169 | n=int(input())
l=list(map(int,input().split()))
d={}
for i in l:
if( i not in d):
d[i]=1
else:
d[i]+=1
m=0
for i in d:
if(d[i]>m):
m=d[i]
print(m,len(set(l))) | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
37/A | 37 | A | Python 3 | TESTS | 57 | 218 | 307,200 | 69073531 | n = int(input())
l = sorted(list(map(int, input().split())))
p = 1
i = 0
maxlen = 0
while(i < (len(l)-1)):
if(l[i] == l[i+1]):
p += 1
else:
p = 1
maxlen = max(maxlen, p)
i += 1
print(maxlen, len(set(l))) | 61 | 92 | 0 | 144353764 | n = int(input())
a = [int(x) for x in input().split()]
v = max(a) + 1
b = [0] * v
c = []
for i in a:
b[i] += 1
for i in range(v):
if b[i] > 0:
c.append(b[i])
print(max(c), len(c)) | Codeforces Beta Round 37 | CF | 2,010 | 2 | 256 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | null | null | [{"input": "3\n1 2 3", "output": "1 3"}, {"input": "4\n6 5 6 7", "output": "2 3"}] | 1,000 | ["sortings"] | 61 | [{"input": "3\r\n1 2 3\r\n", "output": "1 3\r\n"}, {"input": "4\r\n6 5 6 7\r\n", "output": "2 3\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "2 3\r\n"}, {"input": "4\r\n1 2 3 3\r\n", "output": "2 3\r\n"}, {"input": "3\r\n20 22 36\r\n", "output": "1 3\r\n"}, {"input": "25\r\n47 30 94 41 45 20 96 51 110 129 24 116 9 47... | false | stdio | null | true |
469/B | 469 | B | PyPy 3-64 | TESTS | 5 | 61 | 0 | 222998911 | p,q,l,r = map(int,input().split())
masters = []
for _ in range(p):
x = list(map(int,input().split()))
masters.append((x[0],x[1]))
moments = (r-l+1)*[0]
for _ in range(q):
x = list(map(int,input().split()))
for master in masters:
ind1 = master[0] -x[1]
ind2 = master[1] - x[0]
ind... | 31 | 46 | 307,200 | 7877172 | x1=[]
x2=[]
p, q, l, r = map(int, input().split(' '))
for i in range(p):
a, b = map(int, input().split(' '))
x1.append([a, b])
for i in range(q):
a, b = map(int, input().split(' '))
x2.append([a, b])
ok2 = []
for a in x1:
for b in x2:
lo = a[0]-b[1]
hi = a[1]-b[0]
if hi >=... | Codeforces Round 268 (Div. 2) | CF | 2,014 | 1 | 256 | Chat Online | Little X and Little Z are good friends. They always chat online. But both of them have schedules.
Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the ti... | The first line contains four space-separated integers p, q, l, r (1 ≤ p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000).
Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000).
It's guaranteed that bi < ai + 1 ... | Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation. | null | null | [{"input": "1 1 0 4\n2 3\n0 1", "output": "3"}, {"input": "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "output": "20"}] | 1,300 | ["implementation"] | 31 | [{"input": "1 1 0 4\r\n2 3\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2 3 0 20\r\n15 17\r\n23 26\r\n1 4\r\n7 11\r\n15 17\r\n", "output": "20\r\n"}, {"input": "5 2 27 452\r\n148 154\r\n421 427\r\n462 470\r\n777 786\r\n969 978\r\n245 247\r\n313 322\r\n", "output": "54\r\n"}, {"input": "3 6 25 785\r\n273 275\r\n391 397\r... | false | stdio | null | true |
370/B | 370 | B | Python 3 | TESTS | 13 | 280 | 1,024,000 | 76299384 | from math import *
from copy import *
from string import * # alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import * # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter # d = dict(Counter(l))
n=int(input())
... | 24 | 62 | 204,800 | 141569418 | n = int(input())
a = [set(list(map(int,input().split()))[1:])for _ in range(n)]
res = 0
print(*['YES'if sum(i.issubset(j)for i in a) == 1 else 'NO' for j in a],sep = '\n') | Codeforces Round 217 (Div. 2) | CF | 2,013 | 1 | 256 | Berland Bingo | Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers.
During the game the host takes num... | The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, ... | Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise. | null | null | [{"input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES"}, {"input": "2\n1 1\n1 1", "output": "NO\nNO"}] | 1,300 | ["implementation"] | 24 | [{"input": "3\r\n1 1\r\n3 2 4 1\r\n2 10 11\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "NO\r\nNO\r\n"}, {"input": "1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2\r\n1 3\r\n", "output": "YES\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n2 1 2\r\n", "output": "YES\r\nNO\r\n"}, {"i... | false | stdio | null | true |
37/B | 37 | B | PyPy 3-64 | TESTS | 1 | 78 | 1,331,200 | 141886178 | n, mx, rg = map(int, input().split())
hp = mx * 1
r = []
for i in range(n):
pw, dm = map(int, input().split())
r.append([(mx * pw) // 100, dm, i])
r.sort(key=lambda x: (x[1], x[0]))
log = []
cast = 0
for time in range(5000):
hp -= cast
if hp <= 0:
print("YES")
print(time+1, len(log))
... | 95 | 109 | 307,200 | 93943052 | import itertools
import math
N, x, y = [int(n) for n in input().split()]
pills = []
for i in range(N):
pills.append(tuple(int(n) for n in input().split()) + (i+1,))
pills.sort()
rques = x
qauto = 0
time = 0
used = []
possible = set()
while rques > 0:
while len(pills) > 0 and pills[-1][0] >= 100*rques/... | Codeforces Beta Round 37 | CF | 2,010 | 1 | 256 | Computer Game | Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.
While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:
1) The boss has t... | The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000). | In case Petya can’t complete this level, output in the single line NO.
Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the... | null | null | [{"input": "2 10 3\n100 3\n99 1", "output": "NO"}, {"input": "2 100 10\n100 11\n90 9", "output": "YES\n19 2\n0 1\n10 2"}] | 1,800 | ["greedy", "implementation"] | 95 | [{"input": "2 10 3\r\n100 3\r\n99 1\r\n", "output": "NO\r\n"}, {"input": "2 100 10\r\n100 11\r\n90 9\r\n", "output": "YES\r\n19 2\r\n0 1\r\n10 2\r\n"}, {"input": "10 100 5\r\n61 3\r\n55 2\r\n12 6\r\n39 5\r\n21 10\r\n39 7\r\n16 1\r\n10 1\r\n70 5\r\n100 7\r\n", "output": "YES\r\n21 6\r\n0 10\r\n15 9\r\n17 1\r\n18 2\r\n19... | false | stdio | null | true |
492/C | 492 | C | PyPy 3-64 | TESTS | 5 | 748 | 19,865,600 | 215374215 | n, r, avg = map(int, input().split())
info = []
for i in range(n):
a, b = map(int, input().split())
info.append([a,b])
exams = sorted(info, key=lambda x: x[1])
summ = 0
for i in exams:
summ += i[0]
halan = summ/n
ans = 0
for ex in exams:
while ex[0]<r and halan<avg:
halan += 1/n
ex[0]... | 39 | 373 | 8,192,000 | 8916892 | from sys import stdin
def main():
n, r, avg = map(int, stdin.readline().strip().split())
aa, bb = [], []
for _ in range(n):
a, b = map(int, stdin.readline().strip().split())
aa.append(a)
bb.append(b)
now = sum(aa)
ineed = n * avg
if now >= ineed:
return 0
pr... | Codeforces Round 280 (Div. 2) | CF | 2,014 | 1 | 256 | Vanya and Exams | Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi es... | The first line contains three integers n, r, avg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.
Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106). | In the first line print the minimum number of essays. | null | In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.
In the second sample, Vanya doesn't need to write any essays as his general point average already is above average. | [{"input": "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5", "output": "4"}, {"input": "2 5 4\n5 2\n5 2", "output": "0"}] | 1,400 | ["greedy", "sortings"] | 39 | [{"input": "5 5 4\r\n5 2\r\n4 7\r\n3 1\r\n3 2\r\n2 5\r\n", "output": "4\r\n"}, {"input": "2 5 4\r\n5 2\r\n5 2\r\n", "output": "0\r\n"}, {"input": "6 5 5\r\n1 7\r\n2 4\r\n3 5\r\n4 6\r\n5 6\r\n4 7\r\n", "output": "63\r\n"}, {"input": "1 1000000000 1000000\r\n1 1000000\r\n", "output": "999999000000\r\n"}, {"input": "10 10... | false | stdio | null | true |
992/D | 992 | D | PyPy 3 | TESTS | 0 | 124 | 0 | 78081457 | # https://codeforces.com/problemset/problem/992/D
n, k = map(int, input().split())
a = list(map(int, input().split()))
max_ = 10 ** 13 + 1
def get(l, r, x):
min_ = min(l,r)
max_ = max(l,r)
if x <= min_:
return x + 1
if x <= max_:
return min_ + 1
return l+r+1-x... | 134 | 764 | 24,473,600 | 119680757 | n,k=map(int, input().split())
v=list(map(int, input().split()))
pos, pref=[-1], []
ans=0
for i in range(n):
if v[i]!=1:
pos.append(i)
if v[i]==1 and k==1:
ans+=1
if i:
pref.append(pref[-1]+v[i])
else:
pref.append(v[i])
pos.append(n)
m=len(pos)
#print("m",m)
inf=int(2e18+10)
for i in range(1,m-1):
p=1
for... | Codeforces Round 489 (Div. 2) | CF | 2,018 | 2 | 256 | Nastya and a Game | Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $$\frac{p}{s} = k$$, where p is the product of all integers on the given array, s is their sum, and k is a given... | The first line contains two integers n and k (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 105), where n is the length of the array and k is the constant described above.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108) — the elements of the array. | In the only line print the number of subsegments such that the ratio between the product and the sum on them is equal to k. | null | In the first example the only subsegment is [1]. The sum equals 1, the product equals 1, so it suits us because $${ \frac { 1 } { 1 } } = 1$$.
There are two suitable subsegments in the second example — [6, 3] and [3, 8, 1]. Subsegment [6, 3] has sum 9 and product 18, so it suits us because $$\frac{18}{9}=2$$. Subsegme... | [{"input": "1 1\n1", "output": "1"}, {"input": "4 2\n6 3 8 1", "output": "2"}] | 2,100 | ["brute force", "implementation", "math"] | 134 | [{"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n6 3 8 1\r\n", "output": "2\r\n"}, {"input": "94 58\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1\r\... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 211017604 | string = input()
n = int(string[:string.find(' ')])
x = int(string[string.find(' ')+1:])
kol = 0
for i in range(n):
str = input()
a = int(str[str.find(' ')+1:])
if str[0] == '+':
x += a
elif x > a:
x -= a
else:
kol += 1
print(x, kol) | 34 | 31 | 0 | 162326094 | n, x = map(int, input().split())
c = 0
for i in range(n):
s, s1 = [i for i in input().split()]
if s == '+':
x += int(s1)
elif s == '-':
if int(s1) <= x:
x -= int(s1)
else:
c += 1
print(x, c) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
508/A | 508 | A | Python 3 | TESTS | 41 | 389 | 10,649,600 | 222299525 | line = input().split()
n, m, k = int(line[0]), int(line[1]), int(line[2])
board = []
check = False
if n == m == 1:
check = True
for i in range(n+1):
board.append([])
for j in range(m+1):
board[i].append(False)
for i in range(k):
if check:
break
line = input().split()
x, y = int... | 52 | 233 | 8,396,800 | 228570355 | M = []
def check(i, j):
global M
if M[i+1][j] and M[i][j+1] and M[i+1][j+1]:
return True
elif M[i-1][j] and M[i][j+1] and M[i-1][j+1]:
return True
elif M[i-1][j] and M[i][j-1] and M[i-1][j-1]:
return True
elif M[i+1][j] and M[i][j-1] and M[i+1][j-1]:
return True
... | Codeforces Round 288 (Div. 2) | CF | 2,015 | 2 | 256 | Pasha and Pixels | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose an... | The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m... | If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0. | null | null | [{"input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4"}, {"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5"}, {"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0"}] | 1,100 | ["brute force"] | 52 | [{"input": "2 2 4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "4\r\n"}, {"input": "2 3 6\r\n2 3\r\n2 2\r\n1 3\r\n2 2\r\n1 2\r\n1 1\r\n", "output": "5\r\n"}, {"input": "5 3 7\r\n2 3\r\n1 2\r\n1 1\r\n4 1\r\n3 1\r\n5 3\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 3 11\r\n2 1\r\n3 1\r\n1 1\r\n1 3\r\n1 2\r\n2 3\r\n3 3\r\n3... | false | stdio | null | true |
505/C | 505 | C | Python 3 | TESTS | 3 | 311 | 3,584,000 | 9472057 | def main():
n, step = map(int, input().split())
archipelago = [0] * 30001
for _ in range(n):
archipelago[int(input())] += 1
le = len(archipelago)
way = [0] * le
lim = min(step * (step + 1) // 2, le)
next = {(0, step)}
while next:
cur, next = next, set()
for x, ste... | 54 | 732 | 66,457,600 | 118800839 | import sys
input=sys.stdin.readline
n,d=map(int,input().split())
p=[int(input()) for i in range(n)]
N=30000
M=500
cnt=[0]*(N+1)
for pp in p:
cnt[pp]+=1
dp=[[-1]*(M+1) for i in range(N+1)]
dp[d][250]=cnt[d]
ans=0
for i in range(d,N+1):
for j in range(M+1):
if dp[i][j]==-1:
continue
id... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta, the Treasure Hunter | The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.... | The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤... | Print the maximum number of gems that Mr. Kitayuta can collect. | null | In the first sample, the optimal route is 0 → 10 (+1 gem) → 19 → 27 (+2 gems) → ...
In the second sample, the optimal route is 0 → 8 → 15 → 21 → 28 (+1 gem) → 36 (+1 gem) → 45 (+1 gem) → 55 (+1 gem) → 66 (+1 gem) → 78 (+1 gem) → ...
In the third sample, the optimal route is 0 → 7 → 13 →... | [{"input": "4 10\n10\n21\n27\n27", "output": "3"}, {"input": "8 8\n9\n19\n28\n36\n45\n55\n66\n78", "output": "6"}, {"input": "13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30", "output": "4"}] | 1,900 | ["dfs and similar", "dp", "two pointers"] | 54 | [{"input": "4 10\r\n10\r\n21\r\n27\r\n27\r\n", "output": "3\r\n"}, {"input": "8 8\r\n9\r\n19\r\n28\r\n36\r\n45\r\n55\r\n66\r\n78\r\n", "output": "6\r\n"}, {"input": "13 7\r\n8\r\n8\r\n9\r\n16\r\n17\r\n17\r\n18\r\n21\r\n23\r\n24\r\n24\r\n26\r\n30\r\n", "output": "4\r\n"}, {"input": "8 4\r\n9\r\n15\r\n15\r\n16\r\n22\r\n2... | false | stdio | null | true |
556/B | 556 | B | PyPy 3-64 | TESTS | 0 | 30 | 0 | 190145057 | n=int(input())
a=list(map(int,input().split()))
for i in range(n):
if (a[i]-a[0]*(-1)**i)%n!=0:
print('No')
break
else:
print('Yes') | 50 | 62 | 0 | 11790698 | from itertools import cycle
n = int(input())
l = list(map(int, input().split(' ')))
times_to_rotate = n - l[0]
for count, (i, mul) in enumerate(zip(l, cycle([1, -1]))):
j = (i + times_to_rotate*mul) % n
if j != count:
print('No')
break
else:
print('Yes') | Codeforces Round 310 (Div. 2) | CF | 2,015 | 2 | 256 | Case of Fake Numbers | Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers f... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of gears.
The second line contains n digits a1, a2, ..., an (0 ≤ ai ≤ n - 1) — the sequence of active teeth: the active tooth of the i-th gear contains number ai. | In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise. | null | In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2. | [{"input": "3\n1 0 0", "output": "Yes"}, {"input": "5\n4 2 1 4 3", "output": "Yes"}, {"input": "4\n0 2 3 1", "output": "No"}] | 1,100 | ["brute force", "implementation"] | 50 | [{"input": "3\r\n1 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n4 2 1 4 3\r\n", "output": "Yes\r\n"}, {"input": "4\r\n0 2 3 1\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "Yes\r\n"}, {"input": "2\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n2 4 4 1 1\r\n", "output": "Yes\r\n"}, {"input": "10\r\... | false | stdio | null | true |
15/A | 15 | A | Python 3 | TESTS | 7 | 92 | 0 | 218694434 | n, t = map(int, input().split())
spots = 0
for i in range(n):
x, a = map(int, input().split())
start = x - int(a / 2)
if i != 0:
if t < start - end:
spots += 2
elif t == start - end:
spots += 1
end = x + int(a / 2)
print(spots + 2) | 35 | 92 | 0 | 152420250 | class Info:
def __init__(self, _left, _right):
self.left = _left
self.right = _right
def __str__(self):
return f'[left: {self.left}, right: {self.right}]'
def output(cont):
for obj in cont:
print(obj)
cont, ans = [], 2
n, t = [int(it) for it in input().split(' ')]
for i ... | Codeforces Beta Round 15 | ICPC | 2,010 | 2 | 64 | Cottage Village | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Pe... | The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). | Output the amount of possible positions of the new house. | null | It is possible for the x-coordinate of the new house to have non-integer value. | [{"input": "2 2\n0 4\n6 2", "output": "4"}, {"input": "2 2\n0 4\n5 2", "output": "3"}, {"input": "2 3\n0 4\n5 2", "output": "2"}] | 1,200 | ["implementation", "sortings"] | 35 | [{"input": "2 2\r\n0 4\r\n6 2\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 4\r\n5 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n0 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n1 1\r\n", "output": "2\r\n"}, {"i... | false | stdio | null | true |
15/A | 15 | A | Python 3 | TESTS | 7 | 92 | 0 | 218122516 | n, need_size = map(int, input().split())
l_house = []
pos_count = 2 # крайние левая и правая позиция дома
for _ in range(n):
l_house.append([int(y) for y in input().split()])
for i in range(n - 1):
dist = l_house[i + 1][0] - l_house[i + 1][1] / 2 - (l_house[i][0] + l_house[i][1] / 2)
if dist == need_size:
... | 35 | 92 | 0 | 152420257 | class Info:
def __init__(self, _left, _right):
self.left = _left
self.right = _right
def __str__(self):
return f"[left: {self.left}, right: {self.right}]"
n, t = list(map(int, input().split(' ')))
cont, ans = [], 2
for i in range(n):
center, size = list(map(int, input().split(' ')... | Codeforces Beta Round 15 | ICPC | 2,010 | 2 | 64 | Cottage Village | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Pe... | The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). | Output the amount of possible positions of the new house. | null | It is possible for the x-coordinate of the new house to have non-integer value. | [{"input": "2 2\n0 4\n6 2", "output": "4"}, {"input": "2 2\n0 4\n5 2", "output": "3"}, {"input": "2 3\n0 4\n5 2", "output": "2"}] | 1,200 | ["implementation", "sortings"] | 35 | [{"input": "2 2\r\n0 4\r\n6 2\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 4\r\n5 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n0 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n1 1\r\n", "output": "2\r\n"}, {"i... | false | stdio | null | true |
15/A | 15 | A | Python 3 | TESTS | 7 | 60 | 0 | 211672338 | n, t = map(int, input().split())
res=2
houses=[]
for i in range(0, n, 1):
houses.append(list(map(int, input().split())))
for i in range(0, len(houses), 1):
if i!=0 and (houses[i][0]-(houses[i][1]/2))-(houses[i-1][0]+(houses[i-1][1]/2))>t:
res+=2
elif i!=0 and (houses[i][0]-(houses[i][1]/2))-(houses[... | 35 | 92 | 0 | 159318196 | j=lambda:list(map(int,input().split()))
n,t=j()
x=sorted(j()for b in'0'*n)
a=0
for i in range(n-1):
l=x[i][0]+t+(x[i][1]+x[i+1][1])/2;r=x[i+1][0]
if l==r:a+=1
if l<r:a+=2
print(a+2) | Codeforces Beta Round 15 | ICPC | 2,010 | 2 | 64 | Cottage Village | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Pe... | The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). | Output the amount of possible positions of the new house. | null | It is possible for the x-coordinate of the new house to have non-integer value. | [{"input": "2 2\n0 4\n6 2", "output": "4"}, {"input": "2 2\n0 4\n5 2", "output": "3"}, {"input": "2 3\n0 4\n5 2", "output": "2"}] | 1,200 | ["implementation", "sortings"] | 35 | [{"input": "2 2\r\n0 4\r\n6 2\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 4\r\n5 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n0 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n1 1\r\n", "output": "2\r\n"}, {"i... | false | stdio | null | true |
962/F | 962 | F | PyPy 3 | TESTS | 4 | 78 | 0 | 152691407 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def lowlink():
o, parent, dist, B = dfs(1)
l = [n + 1] * (n + 1)
for i in range(n + 1):
l[i] = o[i]
for i in range(n + 1):
for j in B[i]:
l[i] = min(l[i], l[j])
x = [[] for _ in range(n + 2)]... | 42 | 857 | 40,243,200 | 129765854 | import sys
def solve():
n, m = map(int, input().split())
g = [[] for i in range(n+1)]
E = [None]*m
for i in range(m):
u, v = map(int, input().split())
E[i] = (u, v)
g[u].append([v,i])
g[v].append([u,i])
P = [-1]*(n+1)
I = [0]*(n+1)
st = []
D = [0]*(n+1)
W = [0]*(n+1)
S = [-1]*m
U = [-1]*m
V = [-1]*... | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Simple Cycles Edges | You are given an undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself).
A cycle in a graph is called a simple, if ... | The first line contain two integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 100\,000$$$, $$$0 \le m \le \min(n \cdot (n - 1) / 2, 100\,000))$$$ — the number of vertices and the number of edges.
Each of the following $$$m$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the descr... | In the first line print the number of edges, which belong to exactly one simple cycle.
In the second line print the indices of edges, which belong to exactly one simple cycle, in increasing order. The edges are numbered from one in the same order as they are given in the input. | null | null | [{"input": "3 3\n1 2\n2 3\n3 1", "output": "3\n1 2 3"}, {"input": "6 7\n2 3\n3 4\n4 2\n1 2\n1 5\n5 6\n6 1", "output": "6\n1 2 3 5 6 7"}, {"input": "5 6\n1 2\n2 3\n2 4\n4 3\n2 5\n5 3", "output": "0"}] | 2,400 | ["dfs and similar", "graphs", "trees"] | 42 | [{"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "6 7\r\n2 3\r\n3 4\r\n4 2\r\n1 2\r\n1 5\r\n5 6\r\n6 1\r\n", "output": "6\r\n1 2 3 5 6 7 \r\n"}, {"input": "5 6\r\n1 2\r\n2 3\r\n2 4\r\n4 3\r\n2 5\r\n5 3\r\n", "output": "0\r\n\r\n"}, {"input": "4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 1\r\n1 3\r\n"... | false | stdio | null | true |
493/A | 493 | A | PyPy 3 | TESTS | 11 | 139 | 0 | 83194155 | #input=__import__('sys').stdin.readline
h = input()
aw = input()
n = int(input())
team=[[0,0] for i in range(200)]
ans=[]
for i in range(n):
a,b,c,d = map(str,input().split())
a = int(a)
c = int(c)
if b=='h':
if d=='y':
team[c][0]+=1
elif team[c][0]<2:
team[c][0]=... | 18 | 46 | 0 | 136966501 | import sys
def read_input(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, 'r')
# n, home, away = f.readline().rstrip().split()
# n = int(n)
home = f.readline().rstrip()
away = f.readline().rstrip()
n = int(f.readline())
fouls = []
... | Codeforces Round 281 (Div. 2) | CF | 2,014 | 2 | 256 | Vasya and Football | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1 ≤ n ≤ 90) — the... | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs;
- the player's number in his team;
- the minute when he received the card.
If no player received a card, then you do not need to pr... | null | null | [{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}] | 1,300 | ["implementation"] | 18 | [{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\... | false | stdio | null | true |
416/B | 416 | B | Python 3 | TESTS | 5 | 545 | 1,740,800 | 74571133 | n,m=map(int,input().split())
c=0
f=[]
h=[0]*(m-1)
final=[]
for j in range(n):
d=list(map(int,input().split()))[:m]
if j==0:
c=sum(d)
final.append(c)
f+=d
else:
for i in range(len(f)-1):
h[i]+=(sum(f[i+1::]))
for i in range(len(h)):
if d[i]<=h[i... | 26 | 155 | 16,486,400 | 196195827 | # Problem A
import sys, functools, string
input = lambda: sys.stdin.readline()[:-1]
get_int = lambda: int(input())
get_int_list = lambda: list(map(int,input().split()))
def solve(m,n,p):
time = [0]*n
ans = []
for i in range(m):
t = 0
for j in range(n):
t = max(time[j],t) + ... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Art Union | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1... | The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to... | Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture. | null | null | [{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}] | 1,300 | ["brute force", "dp", "implementation"] | 26 | [{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5... | false | stdio | null | true |
754/D | 754 | D | PyPy 3 | TESTS | 4 | 140 | 0 | 41441070 | n, k = map(int, input().split())
arr = []
for i in range(n):
l, r = map(int, input().split())
arr.append((l, -1, i))
arr.append((r, 1, i))
arr.sort()
ans = 0
ind = []
tot = 0
l, r = 10 ** 19, 0
temp = set()
for a in arr:
tot -= a[1]
if tot >= k:
if a[1] == -1:
temp.add(a[2])... | 77 | 1,122 | 74,240,000 | 174840382 | import sys
from heapq import *
input = sys.stdin.readline
n, k = map(int, input().split())
a = []
for i in range(n):
l, r = map(int, input().split())
a.append((l, r, i))
a.sort(key=lambda p: p[0])
ans = ll = 0
h = [p[1] for p in a[:k]]
heapify(h)
d = h[0] - a[k - 1][0] + 1
if d > ans:
ans = d
ll = a[k... | Codeforces Round 390 (Div. 2) | CF | 2,017 | 4 | 256 | Fedor and coupons | All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.
The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with i... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose.
Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal. | In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted.
In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should c... | null | In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total.
In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example. | [{"input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2"}, {"input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2"}, {"input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4"}] | 2,100 | ["binary search", "data structures", "greedy", "sortings"] | 77 | [{"input": "4 2\r\n1 100\r\n40 70\r\n120 130\r\n125 180\r\n", "output": "31\r\n1 2 \r\n"}, {"input": "3 2\r\n1 12\r\n15 20\r\n25 30\r\n", "output": "0\r\n1 2 \r\n"}, {"input": "5 2\r\n1 10\r\n5 15\r\n14 50\r\n30 70\r\n99 100\r\n", "output": "21\r\n3 4 \r\n"}, {"input": "7 6\r\n-8 6\r\n7 9\r\n-10 -5\r\n-6 10\r\n-7 -3\r\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, k = map(int, f.readline().split())
coupons = []
for _ in range(n):
l, r = map(int, f.readline().split())
... | true |
730/G | 730 | G | Python 3 | TESTS | 11 | 61 | 0 | 31978812 | # -*- coding: utf-8 -*-
"""
Created on Thu Nov 2 15:41:39 2017
@author: savit
"""
n=int(input())
a=[]
pos=1
curr=[]
for i in range(n):
c=list(map(int,input().split()))
a.append([c[0],c[0]+c[1]-1,i])
for i in range(n):
org=True
for j in range(len(curr)):
if(a[i][0]<=curr[j][1]<=a[i][1] or a[i][... | 28 | 77 | 307,200 | 21705313 | from bisect import bisect_left, insort_left
a = []
n = int(input())
for _ in range(n):
#print(a)
s, d = map(int, input().split())
if len(a) == 0:
print(s, s+d - 1)
a.append((s, s + d - 1))
continue
p = bisect_left(a, (s, s + d - 1))
#print('p', p)
ok = True
if p > 0 a... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
774/D | 774 | D | Python 3 | TESTS | 7 | 62 | 4,608,000 | 174842854 | n, l, r = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
a1=a2=a3=b1=b2=b3=None
if l==1:
a2=a[0:r]
a3=a[r::]
b2=b[0:r]
b3=b[r::]
elif l==2:
a1=a[0]
a2=a[1:r]
a3=a[r::]
b1=b[0]
b2=b[1:r]
b3=b[r::]
... | 52 | 78 | 15,155,200 | 26148356 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
n, l, r = input().split()
n = int(n)
l = int(l)
r = int(r)
past = input().split()
cur = input().split()
if (past[:l-1] != cur[:l-1]) or (past[r:] != cur[r:]):
print('LIE')
else:
print('TRUTH') | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 2 | 256 | Lie or Truth | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.
While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan... | The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order.
The third line contains the sequence b1, b2, ... | Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes). | null | In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and... | [{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}] | 1,500 | ["*special", "constructive algorithms", "implementation", "sortings"] | 52 | [{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ... | false | stdio | null | true |
424/B | 424 | B | PyPy 3 | TESTS | 22 | 155 | 0 | 70111358 | n,pop = list(map(int,input().split()))
arr = []
d = {}
cnt = 0
for i in range(n):
x,y,p = list(map(int,input().split()))
x,y = abs(x),abs(y)
cnt+=p
arr.append([x,y,p])
r = (x**2 + y**2)**(0.5)
d[r] = i
keys = list(d.keys())
keys.sort()
if pop+cnt<1000000:
print(-1)
else:
cnt = 0
for ... | 54 | 61 | 0 | 136965589 | import sys
import math
def read_input(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, 'r')
n, p = map(int, f.readline().split())
cities = list()
for _ in range(n):
x, y, a = map(int, f.readline().split())
cities.append((x, y, a))
... | Codeforces Round 242 (Div. 2) | CF | 2,014 | 2 | 256 | Megacity | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | null | null | [{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}] | 1,200 | ["binary search", "greedy", "implementation", "sortings"] | 54 | [{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.read().strip()
with open(submission_path, 'r') as f:
sub_line = f.read().strip()
if ref_line == '-1':
if sub_line... | true |
545/C | 545 | C | Python 3 | TESTS | 10 | 343 | 14,848,000 | 229505811 | n=int(input())
tree={}
cdn=[0]
for i in range(1,n+1):
x,h=map(int,input().split())
cdn.append(x)
tree[x]=h
cdn=sorted(cdn)#看了评测数据发现x已经排序好了
flag=[0]*(n+1)
for i in range(2,n):#太高的树直接不管
if tree[cdn[i]]<cdn[i]-cdn[i-1]:#能向左倒flag+1
flag[i]+=1
if tree[cdn[i]]<cdn[i+1]-cdn[i]:#能向右倒flag+2
f... | 67 | 108 | 3,993,600 | 199207168 | from sys import stdin,stdout
input,print = stdin.readline,stdout.write
n=int(input())
back=-10**9
prev=-1
count=0
for i in range(n):
pos,curr=map(int,input().split())
#print(str(back),str(prev),str(pos),str(curr),str(count))
dist=pos-back
if prev==-1:
if curr<dist:
count+=1
... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Woodcutters | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | The first line contains integer n (1 ≤ n ≤ 105) — the number of trees.
Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree.
The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | null | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1]
- fell the 2-nd tree to the right — now it occupies segment [2;3]
- leave the 3-rd tree — it occupies point 5
- leave the 4-th tree — it occupies point 10
- fell the 5-th tree to the right — now it... | [{"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3"}, {"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4"}] | 1,500 | ["dp", "greedy"] | 67 | [{"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n19 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n20 1\r\n", "output": "4\r\n"}, {"input": "4\r\n10 4\r\n15 1\r\n19 3\r\n20 1\r\n", "output": "4\r\n"}, {"input": "35\r\n1 7\r\n3 11\r\n6 12\r\n7 6\r\n8 5\r\n9 11\r\n15 3\r\n16 10\r\n22 2\r\n23 3\r\... | false | stdio | null | true |
545/C | 545 | C | Python 3 | TESTS | 10 | 342 | 6,656,000 | 177844624 | n = int(input())
if n == 1:
print(1)
else:
coordinates = []
height = []
distance = []
num = 2
for i in range(n):
x, h = [int(x) for x in input().split()]
coordinates.append(x)
height.append(h)
for i in range(1, n):
distance.append(coordinates[i] - coordinates[... | 67 | 124 | 10,956,800 | 199863233 | import sys
from os import path
def input():
return sys.stdin.readline().strip()
def solve(l, r):
pass
def main(multiple=False):
n = int(input())
x_array = []
h_array = []
for _ in range(n):
x, h = map(int, input().split())
x_array.append(x)
h_array.append(h)
ans = 1
if n == 1:
prin... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Woodcutters | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | The first line contains integer n (1 ≤ n ≤ 105) — the number of trees.
Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree.
The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | null | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1]
- fell the 2-nd tree to the right — now it occupies segment [2;3]
- leave the 3-rd tree — it occupies point 5
- leave the 4-th tree — it occupies point 10
- fell the 5-th tree to the right — now it... | [{"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3"}, {"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4"}] | 1,500 | ["dp", "greedy"] | 67 | [{"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n19 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n20 1\r\n", "output": "4\r\n"}, {"input": "4\r\n10 4\r\n15 1\r\n19 3\r\n20 1\r\n", "output": "4\r\n"}, {"input": "35\r\n1 7\r\n3 11\r\n6 12\r\n7 6\r\n8 5\r\n9 11\r\n15 3\r\n16 10\r\n22 2\r\n23 3\r\... | false | stdio | null | true |
424/B | 424 | B | PyPy 3 | TESTS | 38 | 139 | 2,150,400 | 116647791 | n,s = map(int,input().split())
d = {}
l = []
for i in range(n):
a,b,c = map(int,input().split())
dist = (a**2 + b**2)**.5
if dist not in d:
l.append([dist,c])
d[dist] = i
else:
l[d[dist]][1] += c
l.sort()
left = 0
right = len(l)-1
ans = -1
for i in range(len(l)):
if s + sum(x... | 54 | 61 | 4,915,200 | 25879699 | import math
n, s = list(map(int, input().split()))
need = 1000000 - s
if need <= 0:
print('0')
exit()
# x, y, pop
c = []
for _ in range(n):
c.append(list(map(int, input().split())))
def getDist(x, y):
return math.sqrt(x * x + y * y)
dist = []
for city in c:
dist.append([getDist(city[0], city[1]), ... | Codeforces Round 242 (Div. 2) | CF | 2,014 | 2 | 256 | Megacity | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | null | null | [{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}] | 1,200 | ["binary search", "greedy", "implementation", "sortings"] | 54 | [{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.read().strip()
with open(submission_path, 'r') as f:
sub_line = f.read().strip()
if ref_line == '-1':
if sub_line... | true |
424/B | 424 | B | PyPy 3 | TESTS | 38 | 124 | 1,945,600 | 116638409 | n,s = map(int,input().split())
d = {}
l = []
for i in range(n):
a,b,c = map(int,input().split())
dist = (a**2 + b**2)**.5
if dist not in d:
l.append([dist,c])
d[dist] = i
else:
l[d[dist]][1] += c
l.sort()
left = 0
right = len(l)-1
ans = -1
while left<=right:
mid = left + (rig... | 54 | 62 | 0 | 120633982 | from math import sqrt
class Place:
def __init__(self, x, y, population):
self.x = x
self.y = y
self.population = population
self.dist = sqrt(x ** 2 + y ** 2)
n, s = map(int, input().split())
places = []
for _ in range(n):
x, y, k = map(int, input().split())
places.append(... | Codeforces Round 242 (Div. 2) | CF | 2,014 | 2 | 256 | Megacity | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | null | null | [{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}] | 1,200 | ["binary search", "greedy", "implementation", "sortings"] | 54 | [{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.read().strip()
with open(submission_path, 'r') as f:
sub_line = f.read().strip()
if ref_line == '-1':
if sub_line... | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 198411858 | loop,ice=list(map(int,input().split()));c=ice;angry=0
for i in range(loop):
pm=list(map(str,input().split()))
if pm[0] == '+':
c+=int(pm[1])
else:
if int(pm[1])>c:
angry+=1
elif c>int(pm[1]):
c-=int(pm[1])
print(c,angry) | 34 | 31 | 0 | 169799034 | m,n=map(int,input().split())
c=0
for i in range(m):
s,p=map(str,input().split())
if s=="+":
n=n+int(p)
elif s=="-":
n=n-int(p)
if n<0:
c=c+1
n=n+int(p)
print(n, c) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
581/C | 581 | C | PyPy 3-64 | TESTS | 3 | 62 | 0 | 173874132 | n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True, key=lambda x: x % 10)
s = 0
for i in range(n):
if a[i] == 100:
s += 10
a[i] = 0
continue
add = 10 - (a[i] % 10)
used = min(k, add)
k -= used
a[i] += used
s += a[i] // 10
a[i] = 100 - a[i]
if k <= 0: break
for i i... | 98 | 202 | 5,427,200 | 13271818 | n, k = map(int, input().split())
sum = 0
arr = list(map(int, input().split()))
for i in range (0, n):
sum = sum + arr[i] // 10
temp = arr[i] // 10
arr[i] = temp * 10 + 10 - arr[i]
arr.sort()
for i in range (0, n):
if k >= arr[i]:
k = k - arr[i]
sum = sum + 1
else:
bre... | Codeforces Round 322 (Div. 2) | CF | 2,015 | 1 | 256 | Developing Skills | Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is... | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-... | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | null | In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} r... | [{"input": "2 4\n7 9", "output": "2"}, {"input": "3 8\n17 15 19", "output": "5"}, {"input": "2 2\n99 100", "output": "20"}] | 1,400 | ["implementation", "math", "sortings"] | 98 | [{"input": "2 4\r\n7 9\r\n", "output": "2\r\n"}, {"input": "3 8\r\n17 15 19\r\n", "output": "5\r\n"}, {"input": "2 2\r\n99 100\r\n", "output": "20\r\n"}, {"input": "100 10000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | false | stdio | null | true |
416/B | 416 | B | Python 3 | TESTS | 5 | 514 | 11,776,000 | 176820143 | import math
# a, b = map(int, input().split())
# a = list(map(int, input().split()))
pictures, painters = map(int, input().split())
time = []
sparetime = [0] * painters
stackans = [0]
for i in range(0, pictures):
f = [int(x) for x in input().split()]
# time[tranh][thoi gian ve cua i-th painter]
time.append(... | 26 | 186 | 22,016,000 | 174800675 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
ans = [[0] * (m + 1) for i in range(n + 1)]
for i in range(1, n + 1):
ans[i][1] = ans[i - 1][1] + l[i - 1][0]
for j in range(2, m + 1):
ans[i][j] = max(... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Art Union | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1... | The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to... | Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture. | null | null | [{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}] | 1,300 | ["brute force", "dp", "implementation"] | 26 | [{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5... | false | stdio | null | true |
416/B | 416 | B | Python 3 | TESTS | 5 | 545 | 15,360,000 | 127469003 | # -*- coding: utf-8 -*-
"""Untitled107.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/191oFh4XTZ0nszEX2Dxo1E3S6Tb3kkBEF
"""
l1=list(map(int,input().split()))
m=l1[0]
n=l1[1]
l1=[]
for x in range(0,m):
l2=list(map(int,input().split()))
l1.app... | 26 | 202 | 20,275,200 | 163990948 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
g = [list(map(int, input().split())) for _ in range(n)]
d = [[0]*m for _ in range(n)]
for i in range(n):
for j in range(m):
if i == 0 and j == 0:
d[i][j] = g[i][j]
elif i == 0:
d[i][j] = d[i][j-1] + g[i][... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Art Union | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1... | The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to... | Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture. | null | null | [{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}] | 1,300 | ["brute force", "dp", "implementation"] | 26 | [{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5... | false | stdio | null | true |
779/C | 779 | C | Python 3 | TESTS | 45 | 732 | 24,268,800 | 42887966 | n, k = [int(x) for x in input().split()]
discounted = [int(x) for x in input().split()]
regular = [int(x) for x in input().split()]
prices = zip(discounted, regular)
prices = sorted(prices, key=lambda x: x[0])
prices = sorted(prices, key=lambda x: x[0]-x[1])
# print(prices)
k_cost = sum(x[0] for x in prices[:k])
... | 67 | 218 | 35,840,000 | 233476689 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = sorted([b_el - a_el for b_el, a_el in zip(b, a) if b_el - a_el < 0])
print(sum(a) + sum(d[:n - k])) | Codeforces Round 402 (Div. 2) | CF | 2,017 | 2 | 256 | Dishonest Sellers | Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.
Not all of sellers are honest, so now some products could be more expensive than after a week of discou... | In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now).
The third... | Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. | null | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ... | [{"input": "3 1\n5 4 6\n3 1 5", "output": "10"}, {"input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25"}] | 1,200 | ["constructive algorithms", "greedy", "sortings"] | 67 | [{"input": "3 1\r\n5 4 6\r\n3 1 5\r\n", "output": "10\r\n"}, {"input": "5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n", "output": "25\r\n"}, {"input": "1 0\r\n9\r\n8\r\n", "output": "8\r\n"}, {"input": "2 0\r\n4 10\r\n1 2\r\n", "output": "3\r\n"}, {"input": "4 2\r\n19 5 17 13\r\n3 18 8 10\r\n", "output": "29\r\n"}, {"input": "5 ... | false | stdio | null | true |
780/D | 780 | D | Python 3 | PRETESTS | 2 | 62 | 4,915,200 | 25242875 | def bin(a, n):
v = a[:]
if len(a) == n:
if a not in pos:
pos.append(a)
else:
a.append(0)
bin(a, n)
v.append(1)
bin(v, n)
n = int(input())
ar = []
global pos
pos = [[0 for i in range(n)]]
bin([], n)
t = True
for i in range(n):
a = input().split()
... | 41 | 109 | 24,473,600 | 25262702 | from sys import stdin, stdout
n = int(stdin.readline())
ans = [0 for i in range(n)]
challengersupd = []
challengers = []
used = set()
d = {}
for i in range(n):
challengers.append(stdin.readline().strip())
d[challengers[-1]] = i
challengers.sort()
label = 1
i = 0
while i < n:
l = i
r = n
... | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Innokenty and a Football League | Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.
Each club's full name consist of two wo... | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.
Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20. | It it is not possible to choose short names and satisfy all constraints, print a single line "NO".
Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.
If there are multiple answe... | null | In the first sample Innokenty can choose first option for both clubs.
In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.
In the third example Innokenty can choose the ... | [{"input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW", "output": "YES\nDIN\nFOO"}, {"input": "2\nDINAMO BYTECITY\nDINAMO BITECITY", "output": "NO"}, {"input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP", "output": "YES\nPLM\nPLS\nGOG"}, {"input": "3\nABC DEF\nABC EFG\nABD OOO", "output": "YES\nABD\nABE\nABO... | 1,900 | ["2-sat", "graphs", "greedy", "implementation", "shortest paths", "strings"] | 41 | [{"input": "2\r\nDINAMO BYTECITY\r\nFOOTBALL MOSCOW\r\n", "output": "YES\r\nDIN\r\nFOO\r\n"}, {"input": "2\r\nDINAMO BYTECITY\r\nDINAMO BITECITY\r\n", "output": "NO\r\n"}, {"input": "3\r\nPLAYFOOTBALL MOSCOW\r\nPLAYVOLLEYBALL SPB\r\nGOGO TECHNOCUP\r\n", "output": "YES\r\nPLM\r\nPLS\r\nGOG\r\n"}, {"input": "3\r\nABC DEF... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
clubs = []
for _ in range(n):
team, hometown = f.readline().strip().split()
clubs.append((team, hometown))
ai_list = []
bi_list = []
f... | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 225609382 | n, x = map(int, input().split())
child = 0
for _ in range(n):
a, b = map(str, input().split())
b = int(b)
if a == "+":
x += b
elif a == "-":
if x - b <= 0:
child += 1
else:
x -= b
print(x, child) | 34 | 31 | 0 | 187680924 | n, x = map(int, input().split())
distressed = 0
for i in range(n):
s, packs = input().split()
if s == '+':
x += int(packs)
elif s == '-' and int(packs) > x:
distressed += 1
else:
x -= int(packs)
print(x, distressed) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 195215617 | n,m = [int(i) for i in input().split()]
d = 0
for i in range(n):
s = input()
op,num = s[0],int(s[1:])
if op=="+":
m += num
elif op=="-":
if m-num>0:
m-=num
else:
d+=1
print(m,d) | 34 | 31 | 0 | 192471612 | count=0
n, h = map(int,input().split())
for i in range(n):
j, k = map(str,input().split())
k=int(k)
if j=='+':h+=k
elif j=='-' and h>=k:h-=k
else:count += 1
print(f"{h} {count}") | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
711/A | 711 | A | Python 3 | TESTS | 4 | 31 | 0 | 216763506 | n=int(input())
s=""
c=0
for i in range(n):
st=input()
if "OO" in st:
c+=1
if c==1:
st=st.replace("OO","++")
s+=st+","
else:
s+=st+","
s=s.split(",")
if c>0:
print("YES")
for i in s:
print(i)
else:
print("NO") | 71 | 46 | 0 | 144333813 | ioi = ''
for i in range(int(input())):
ioi += input() + '\n'
ioi_01 = ioi.replace('OO', '++', 1)
if ioi != ioi_01:
print('YES\n' + ioi_01)
else:
print('NO') | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
580/B | 580 | B | PyPy 3-64 | TESTS | 30 | 873 | 13,312,000 | 213753815 | n, money_diff = map(int, input().split(' '))
money = list()
friendship = list()
l = list()
for i in range(n):
x, y = map(int, input().split(' '))
l.append((x, y))
l = sorted(l)
money = [x for x, _ in l]
friendship = [x for _, x in l]
i = 0
max_friendship = 0
temp_m = 0
for j in range(len(money)):
if money... | 35 | 374 | 14,848,000 | 212251689 | n, d = map(int, input().split())
friends = []
for _ in range(n):
m, s = map(int, input().split())
friends.append((m, s))
friends.sort() # Сортируем друзей по количеству денег
max_money = 0
current_money = 0
left = 0
for right in range(n):
current_money += friends[right][1] # Увеличиваем текущую сумму ... | Codeforces Round 321 (Div. 2) | CF | 2,015 | 2 | 256 | Kefa and Company | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to... | The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, $$1 \leq d \leq 10^9$$) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contai... | Print the maximum total friendship factir that can be reached. | null | In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends. | [{"input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100"}, {"input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111"}] | 1,500 | ["binary search", "sortings", "two pointers"] | 35 | [{"input": "4 5\r\n75 5\r\n0 100\r\n150 20\r\n75 1\r\n", "output": "100\r\n"}, {"input": "5 100\r\n0 7\r\n11 32\r\n99 10\r\n46 8\r\n87 54\r\n", "output": "111\r\n"}, {"input": "1 1000000000\r\n15 12\r\n", "output": "12\r\n"}, {"input": "5 1\r\n5 9\r\n2 10\r\n8 5\r\n18 12\r\n1 1\r\n", "output": "12\r\n"}, {"input": "3 3... | false | stdio | null | true |
545/C | 545 | C | PyPy 3-64 | TESTS | 29 | 639 | 16,998,400 | 208021441 | l=[]
n=int(input())
for _ in range(n):
x,h=map(int,input().split())
l.append([x,h])
if n>1:
x1=1
ans=2
for i in range(1,n-1):
x=l[i][0]
h=l[i][1]
if (x-x1)>h:
ans+=1
x1=x
elif l[i+1][0]-x>h:
ans+=1
x1=x+h
else:
... | 67 | 155 | 17,203,200 | 213677729 | import sys
input = sys.stdin.readline
n = int(input())
ls = []
for i in range(n) :
ls.append(list(map(int,input().split())))
ans = 1
for i in range(1,n-1) :
if ls[i][0] - ls[i-1][0] > ls[i][1] :
ans += 1
elif ls[i+1][0] - ls[i][0] > ls[i][1] :
ans += 1
ls[i][0] += ls[i][1]
print(ans+... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Woodcutters | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | The first line contains integer n (1 ≤ n ≤ 105) — the number of trees.
Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree.
The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | null | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1]
- fell the 2-nd tree to the right — now it occupies segment [2;3]
- leave the 3-rd tree — it occupies point 5
- leave the 4-th tree — it occupies point 10
- fell the 5-th tree to the right — now it... | [{"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3"}, {"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4"}] | 1,500 | ["dp", "greedy"] | 67 | [{"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n19 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n20 1\r\n", "output": "4\r\n"}, {"input": "4\r\n10 4\r\n15 1\r\n19 3\r\n20 1\r\n", "output": "4\r\n"}, {"input": "35\r\n1 7\r\n3 11\r\n6 12\r\n7 6\r\n8 5\r\n9 11\r\n15 3\r\n16 10\r\n22 2\r\n23 3\r\... | false | stdio | null | true |
416/B | 416 | B | PyPy 3 | TESTS | 5 | 670 | 10,035,200 | 77979143 | n,m=map(int,input().split())
l=[]
summ=0
for i in range(n):
l.append(list(map(int,input().split())))
for i in range(n):
for j in range(m):
summ+=l[i][j]
s=sum(l[i][j+1:])
for k in range(i+1,n):
if s>0:
if s>l[k][j]:
s-=l[k][j]
... | 26 | 264 | 10,752,000 | 149945369 | import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
m,n = M()
l = [0]*(n)
for _ in range(m):
arr = L()
l[0]+=arr[0]
for i in range(1,n):
l[i] = max(l[i-1],l[i]) + arr[i]
print(... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Art Union | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1... | The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to... | Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture. | null | null | [{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}] | 1,300 | ["brute force", "dp", "implementation"] | 26 | [{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5... | false | stdio | null | true |
711/A | 711 | A | Python 3 | TESTS | 4 | 31 | 0 | 229113364 | rows = int(input())
c =[]
f = 0
for i in range(rows):
c.append(input())
for i in range(rows):
s = c[i]
if s[:2] == 'OO':
c[i] = s.replace('OO', '++')
print('YES')
f = 1
break
if s[3:] == 'OO':
c[i] = s.replace('OO', '++')
print('YES')
f = 1
... | 71 | 46 | 0 | 144892273 | n = int(input())
seats = []
judge = False
for i in range(n):
seats.append(input())
if 'OO' in seats[i] and not judge:
judge = True
seats[i] = seats[i].replace('OO', '++', 1)
if not judge:
print('NO')
else:
print('YES')
print('\n'.join(seats)) | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
711/A | 711 | A | Python 3 | TESTS | 4 | 31 | 0 | 230303392 | seats = []
trig = True
for _ in range(int(input())):
s = input()
if 'OO' in s and trig:
s = s.replace('OO','++')
trig = False
seats.append(s)
if trig:
print("NO")
else:
print("YES")
for i in seats:
print(i) | 71 | 46 | 0 | 145156761 | s=""
for i in range(int(input())):
s=s+input()
s=s+"\n"
if(s.count('OO')):
print("YES")
print(s.replace('OO','++',1))
else:
print("NO") | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
79/B | 79 | B | Python 3 | TESTS | 4 | 124 | 0 | 138207035 | def waste_search(row, col, n):
if n == 0:
return 0
movingi = n//2
lower_bound = 0
upper_bound = n - 1 # Bounds for moving i
while upper_bound - lower_bound > 1:
if waste[movingi] == (row, col):
return -1
elif waste[movingi][0] > row:
change = max((1, ... | 29 | 92 | 0 | 211049941 | import bisect
n, m, k, t = map(int, input().split())
def id(i, j):
return j + i*m
wastes = []
for ii in range(k):
i, j = map(int, input().split())
wastes.append(id(i-1, j-1))
wastes.sort()
labels = ['Carrots', 'Kiwis', 'Grapes']
for ii in range(t):
i, j = map(int, input().split())
id_gross =... | Codeforces Beta Round 71 | CF | 2,011 | 2 | 256 | Colorful Field | Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following ... | In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k line... | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | null | The sample corresponds to the figure in the statement. | [{"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"}] | 1,400 | ["implementation", "sortings"] | 29 | [{"input": "4 5 5 6\r\n4 3\r\n1 3\r\n3 3\r\n2 5\r\n3 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n1 1\r\n1 1\r\n", "output": "Waste\r\nGrapes\r\nCarrots\r\nKiwis\r\nCarrots\r\nCarrots\r\n"}, {"input": "2 3 2 2\r\n1 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "Carrots\r\nWaste\r\n"}, {"input": "31 31 31 4\r\n15 26\r\n29 15\r\n17 31\r\n2... | false | stdio | null | true |
441/B | 441 | B | Python 3 | TESTS | 9 | 62 | 0 | 9351825 | n, v = [int(x) for x in input().split()]
l = [0] * 3001
for i in range(n):
a, b = [int(x) for x in input().split()]
l[a] += b
ans = 0
for i in range(1, 3001):
left = v
if l[i - 1]:
ans += min(left, l[i - 1])
left -= min(left, l[i - 1])
ans += min(left, l[i])
l[i] -= min(left, l[i])
print(ans) | 51 | 77 | 204,800 | 116666442 | from math import gcd
def take_input(s): #for integer inputs
if s == 1: return int(input())
return map(int, input().split())
n, v = take_input(2)
d = {0:0}
days = 1
for i in range(n):
ai, bi = take_input(2)
d[ai] = d.get(ai,0) + bi
if ai > days:
days = ai
ans = 0
prev_day = 0
for i... | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
441/B | 441 | B | Python 3 | TESTS | 9 | 62 | 0 | 142319318 | n,v=list(map(int,input().split()))
a=[]
for k in range(3002):
a.append([0,0])
for i in range(n):
ai,bi=list(map(int,input().split()))
a[ai][0]=0
a[ai][1]+=bi
ans=0
for i in range(3001):
if a[i][0]+a[i][1]>v:
ans+=v
if a[i][0]>v:
a[i+1][0]=a[i][1]
else:
... | 51 | 77 | 204,800 | 117052931 | n,v = map(int,input().split(' '))
result,day,trees = 0,1,{}
for i in range(n):
days,fruits = map(int,input().split(' '))
if days in trees:
trees[days] += fruits
else: trees[days] = fruits
while day <= 3001:
to_collect = v
if day - 1 in trees:
x = trees[day - 1]
trees[day ... | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
441/B | 441 | B | PyPy 3 | TESTS | 9 | 156 | 23,654,400 | 122423230 | n, v = map(int, input().split())
lst = [0] * 3002
for _ in range(n):
a, b = map(int, input().split())
lst[a] += b
b = lst[:]
t = 0
for day in range(3001):
x = min(v, b[day])
t += x
b[day+1] += min(b[day]-x, lst[day])
print(t) | 51 | 77 | 307,200 | 6843734 | n, v = map(int, input().split())
trees = {}
days = set()
for i in range(n):
a, b = map(int, input().split())
if a not in trees:
trees[a] = b
else:
trees[a] += b
days.add(a)
max_days = max(days)
total = 0
for a in range(1, max_days+1):
# print(a)
# print(tre... | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
441/B | 441 | B | Python 3 | TESTS | 9 | 78 | 307,200 | 6845814 | total_plucked = 0
n,v = list(map(int,input().split()))
fruits = [0] * 3001
plucked = [0] * 30001
for _ in range(n):
a,b = list(map(int,input().split()))
fruits[a] = fruits[a] + b
for i in range(1,3001):
plucked[i] = fruits[i - 1] if (fruits[i - 1] <= v) else v
if(plucked[i] < v):
pluck = fruits[i] ... | 51 | 77 | 307,200 | 15280540 | T = 3333;
n, v = map(int, input().split());
data = [0] * T;
for i in range(0, n):
a, b = map(int, input().split());
data[a] += b;
answer = 0;
for i in range(1, T):
x = v;
tmp = min(v, data[i - 1]);
x -= tmp;
data[i - 1] -= tmp;
answer += tmp;
tmp = min(x, data[i]);
data[i] -= tmp... | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
431/A | 431 | A | Python 3 | TESTS | 5 | 171 | 614,400 | 177365585 | def squares():
ponto = list(input())
for i in ponto:
if i == ' ':
ponto.remove(i)
posicao = list(input())
cont = 0
for i in posicao:
for j in range(len(ponto)):
if (int(i)-1) == j:
cont += int(ponto[j])
print(cont)
squares() | 49 | 46 | 0 | 161229821 | l=list(map(int,input().split()))
ch=input()
print(ch.count("1")*l[0]+ch.count("2")*l[1]+ch.count("3")*l[2]+ch.count("4")*l[3]) | Codeforces Round 247 (Div. 2) | CF | 2,014 | 1 | 256 | Black Square | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104).
The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if... | Print a single integer — the total number of calories that Jury wastes. | null | null | [{"input": "1 2 3 4\n123214", "output": "13"}, {"input": "1 5 3 2\n11221", "output": "13"}] | 800 | ["implementation"] | 49 | [{"input": "1 2 3 4\r\n123214\r\n", "output": "13\r\n"}, {"input": "1 5 3 2\r\n11221\r\n", "output": "13\r\n"}, {"input": "5 5 5 1\r\n3422\r\n", "output": "16\r\n"}, {"input": "4 3 2 1\r\n2\r\n", "output": "3\r\n"}, {"input": "5651 6882 6954 4733\r\n2442313421\r\n", "output": "60055\r\n"}, {"input": "0 0 0 0\r\n4132\r\... | false | stdio | null | true |
508/A | 508 | A | PyPy 3 | TESTS | 27 | 857 | 30,003,200 | 161819604 | n, m, k = map(int, input().split())
S = [[0]*m for i in range(n)]
Q = []
for i in range(k):
y, x = map(int, input().split())
y -= 1
x -= 1
Q.append((y, x))
if n == 1 or m == 1:
print(0)
exit()
for i, (y, x) in enumerate(Q):
S[y][x] = 1
if y-1 >= 0 and x-1 >= 0:
if S[y-1][x-1] ... | 52 | 233 | 8,396,800 | 228671750 | n,m,k=map(int,input().split())
t=[[0]*(n+2) for i in range(m+2)]
for i in range(k):
n,m=map(int,input().split())
t[m][n]=1
c=t[m][n]
if c==t[m-1][n]:
if c==t[m][n-1]:
if c==t[m-1][n-1]:
print(i+1)
break
if c==t[m][n+1]:
if c==t[m-1]... | Codeforces Round 288 (Div. 2) | CF | 2,015 | 2 | 256 | Pasha and Pixels | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose an... | The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m... | If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0. | null | null | [{"input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4"}, {"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5"}, {"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0"}] | 1,100 | ["brute force"] | 52 | [{"input": "2 2 4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "4\r\n"}, {"input": "2 3 6\r\n2 3\r\n2 2\r\n1 3\r\n2 2\r\n1 2\r\n1 1\r\n", "output": "5\r\n"}, {"input": "5 3 7\r\n2 3\r\n1 2\r\n1 1\r\n4 1\r\n3 1\r\n5 3\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 3 11\r\n2 1\r\n3 1\r\n1 1\r\n1 3\r\n1 2\r\n2 3\r\n3 3\r\n3... | false | stdio | null | true |
508/D | 508 | D | Python 3 | TESTS | 2 | 46 | 0 | 181356180 | from collections import defaultdict
words = defaultdict(list)
#words_as_list = []
for _ in range(int(input())):
three = input()
first_two = three[:2]
last_two = three[-2:]
if first_two in words:
words[first_two].append(last_two)
else:
words[first_two] = [last_two]
#words_as_list... | 44 | 1,544 | 27,545,600 | 183431418 | from collections import defaultdict
n = int(input())
subs = [input() for i in range(n)]
in_degree = defaultdict(int)
out_degree = defaultdict(int)
adj = defaultdict(list)
nodes = set()
for sub in subs:
a = sub[:2]
b = sub[1:]
nodes.add(a)
nodes.add(b)
out_degree[a] += 1
in_degree[b] += 1
... | Codeforces Round 288 (Div. 2) | CF | 2,015 | 2 | 256 | Tanya and Password | While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password ... | The first line contains integer n (1 ≤ n ≤ 2·105), the number of three-letter substrings Tanya got.
Next n lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit. | If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO".
If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option. | null | null | [{"input": "5\naca\naba\naba\ncab\nbac", "output": "YES\nabacaba"}, {"input": "4\nabc\nbCb\ncb1\nb13", "output": "NO"}, {"input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa", "output": "YES\naaaaaaaaa"}] | 2,500 | ["dfs and similar", "graphs"] | 44 | [{"input": "5\r\naca\r\naba\r\naba\r\ncab\r\nbac\r\n", "output": "YES\r\nabacaba\r\n"}, {"input": "4\r\nabc\r\nbCb\r\ncb1\r\nb13\r\n", "output": "NO\r\n"}, {"input": "7\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\n", "output": "YES\r\naaaaaaaaa\r\n"}, {"input": "1\r\nabc\r\n", "output": "YES\r\nabc\r\n"}, {"inpu... | false | stdio | import sys
from collections import defaultdict
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
input_substrings = [f.readline().strip() for _ in range(n)]
# Read reference output
with open(output_path) as f:... | true |
711/A | 711 | A | Python 3 | TESTS | 4 | 15 | 0 | 168186662 | ch=""
x=int(input())
for i in range(x):
ch1=input()
ch=ch+ch1+" "
l=ch.split(" ")
l.pop()
for i in range(len(l)):
if "OO" in l[i]:
l[i]=l[i].replace("OO","++")
break
if ("++" in "".join(l)):
print("YES")
for j in l:
print(j)
else:
print("NO") | 71 | 46 | 0 | 146155435 | n = int(input())
l =[]
c = 0
for _ in range(n):
s = list(map(str,input().strip()))
l.append(s)
for x in range(n):
if l[x][0] == "O" and l[x][1]=="O" and c==0:
c += 1
l[x][0] = "+"
l[x][1] = "+"
break
elif l[x][3] == "O" and l[x][4]=="O" and c==0:
c += 1
... | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
730/G | 730 | G | PyPy 3-64 | TESTS | 10 | 46 | 0 | 183441542 | import sys
input = sys.stdin.readline
d = [(0, 0)]
n = 1
for _ in range(int(input())):
a, b = map(int, input().split())
ew = 0
for i, j in d:
if i <= a <= j or i <= a + b - 1 <= j:
ew = 1
break
if ew == 0:
d.append((a, a+b-1))
print(a, a+b-1)
else:
... | 28 | 77 | 2,867,200 | 211349045 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = [0,10**18]
for _ in range(N):
s,d = map(int, input().split())
find = False
for i in range(1,len(A),2):
if A[i]>s+d-1 and A[i-1]<s:
print(s,s+d-1)
A.append(s)
A.append(s+d-1)
... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
471/B | 471 | B | Python 3 | PRETESTS | 5 | 61 | 0 | 7965873 | n = int(input())
A = list(map(int, input().split()))
D = [[] for i in range(2001)]
for i in range(n):
D[A[i]].append(i + 1)
D1 = []
D2 = []
D3 = []
not1 = 0
bla = True
for i in range(1, 2001):
if len(D[i]) >= 3:
D1.extend(D[i])
D2.extend(D[i][::-1])
D3.extend(D[i][len(D[i]) // 2:])
... | 31 | 62 | 409,600 | 8825669 | import sys
import math
n = int(sys.stdin.readline())
hn = [int(x) for x in (sys.stdin.readline()).split()]
a = []
b = []
c = []
d = dict()
for i in range(n):
if hn[i] in d:
d[hn[i]].append(i + 1)
else:
d[hn[i]] = [i + 1]
y = list(d.keys())
y.sort()
f = 0
for i in y:
if(len(d[i]) >... | Codeforces Round 269 (Div. 2) | CF | 2,014 | 1 | 256 | MUH and Important Things | It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order... | The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is. | In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order t... | null | In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer.
In the second sample there are only tw... | [{"input": "4\n1 3 3 1", "output": "YES\n1 4 2 3\n4 1 2 3\n4 1 3 2"}, {"input": "5\n2 4 1 4 8", "output": "NO"}] | 1,300 | ["implementation", "sortings"] | 31 | [{"input": "4\r\n1 3 3 1\r\n", "output": "YES\r\n1 4 2 3 \r\n4 1 2 3 \r\n4 1 3 2 \r\n"}, {"input": "5\r\n2 4 1 4 8\r\n", "output": "NO"}, {"input": "8\r\n1 5 4 12 7 2 10 11\r\n", "output": "NO"}, {"input": "6\r\n5 1 2 5 2 4\r\n", "output": "YES\r\n2 3 5 6 1 4 \r\n2 5 3 6 1 4 \r\n2 5 3 6 4 1 \r\n"}, {"input": "1\r\n1083... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
return [line.strip() for line in f.readlines()]
def main(input_path, output_path, submission_path):
input_lines = read_file(input_path)
n = int(input_lines[0])
h = list(map(int, input_lines[1].split()))
ref_lines = read_file(output... | true |
314/C | 314 | C | Python 3 | TESTS | 8 | 109 | 8,089,600 | 3846375 | class FT:
def __init__(self):
self.data = [0] * 1000009
def add(self, idx, v):
while idx <= len(self.data):
self.data[idx] += v
idx += idx & -idx
def query(self, idx):
ret = 0
while idx > 0:
ret += self.data[idx]
ret... | 24 | 310 | 34,406,400 | 148074888 | BIT = [0] * (1000001)
dp = [0] * (1000001)
MOD = 1000000007
ans = 0
def query(p):
ret = 0
i = p
while i:
ret = (ret + BIT[i]) % MOD
i -= i & -i
return ret
def update(p, v):
i = p
while (i <= 1000000):
BIT[i] = (BIT[i] + v) % MOD
i += i & -i
N = int(input())
arr = ... | Codeforces Round 187 (Div. 1) | CF | 2,013 | 2 | 256 | Sereja and Subsequences | Sereja has a sequence that consists of n positive integers, a1, a2, ..., an.
First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not excee... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106). | In the single line print the answer to the problem modulo 1000000007 (109 + 7). | null | null | [{"input": "1\n42", "output": "42"}, {"input": "3\n1 2 2", "output": "13"}, {"input": "5\n1 2 3 4 5", "output": "719"}] | 2,000 | ["data structures", "dp"] | 24 | [{"input": "1\r\n42\r\n", "output": "42\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "13\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "719\r\n"}, {"input": "4\r\n11479 29359 26963 24465\r\n", "output": "927446239\r\n"}, {"input": "5\r\n5706 28146 23282 16828 9962\r\n", "output": "446395832\r\n"}, {"input": "6\r\n49... | false | stdio | null | true |
546/B | 546 | B | Python 3 | TESTS | 4 | 30 | 0 | 228593204 | n = int(input())
l = list(map(int, input().split(" ")))
j = 0
last = l[0]
l.sort()
for i in range(1,n):
if l[i] <= last:
j += last - l[i] + 1
last += 1
else:
last = l[i]
print(j) | 49 | 62 | 307,200 | 11209019 | n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
c = 0
for i in range(n-1):
if(a[i] >= a[i+1]):
x = a[i+1]
a[i+1] += (a[i]-a[i+1]+1)
c += a[i]-x+1
print(c) | Codeforces Round 304 (Div. 2) | CF | 2,015 | 3 | 256 | Soldier and Badges | Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.
For every pair of soldiers one of them should get a badge with strictly higher factor than the second... | First line of input consists of one integer n (1 ≤ n ≤ 3000).
Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge. | Output single integer — minimum amount of coins the colonel has to pay. | null | In first sample test we can increase factor of first badge by 1.
In second sample test we can increase factors of the second and the third badge by 1. | [{"input": "4\n1 3 1 4", "output": "1"}, {"input": "5\n1 2 3 2 5", "output": "2"}] | 1,200 | ["brute force", "greedy", "implementation", "sortings"] | 49 | [{"input": "4\r\n1 3 1 4\r\n", "output": "1"}, {"input": "5\r\n1 2 3 2 5\r\n", "output": "2"}, {"input": "5\r\n1 5 3 2 4\r\n", "output": "0"}, {"input": "10\r\n1 1 2 3 4 5 6 7 8 9\r\n", "output": "9"}, {"input": "11\r\n9 2 10 3 1 5 7 1 4 8 6\r\n", "output": "10"}, {"input": "4\r\n4 3 2 2\r\n", "output": "3"}, {"input":... | false | stdio | null | true |
321/B | 321 | B | Python 3 | TESTS | 27 | 124 | 5,632,000 | 33548356 | jiro, ciel = map(int, input().split())
jiro_ATK = []
jiro_DEF = []
for a in range(jiro) :
position, streng = input().split()
if position == "ATK" :
jiro_ATK.append(int(streng))
else :
jiro_DEF.append(int(streng))
jiro_DEF.sort();
jiro_ATK.sort();
ciel_cards = []
for a in range(ciel) :
ciel_cards.append... | 80 | 248 | 0 | 46017799 | n , m = map(int , input().split())
a , d = [1e9] , [1e9]
for x in range(n) :
p , s = input().split()
[d , a][p < 'B'].append(int(s))
v = [int(input()) for y in range(m) ]
for q in [a , d , v] : q.sort()
s = sum(v)
i = j = 0
for t in v :
if t > d[i] : s , i = s - t , i + 1
elif t >= a[j] : s , j = s - a... | Codeforces Round 190 (Div. 1) | CF | 2,013 | 2 | 256 | Ciel and Duel | Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following ope... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for... | Output an integer: the maximal damage Jiro can get. | null | In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage ... | [{"input": "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "output": "3000"}, {"input": "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "output": "992"}, {"input": "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "output": "1"}] | 1,900 | ["dp", "flows", "greedy"] | 80 | [{"input": "2 3\r\nATK 2000\r\nDEF 1700\r\n2500\r\n2500\r\n2500\r\n", "output": "3000\r\n"}, {"input": "3 4\r\nATK 10\r\nATK 100\r\nATK 1000\r\n1\r\n11\r\n101\r\n1001\r\n", "output": "992\r\n"}, {"input": "2 4\r\nDEF 0\r\nATK 0\r\n0\r\n0\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\nATK 100\r\n99\r\n", "output"... | false | stdio | null | true |
321/B | 321 | B | PyPy 3 | TESTS | 28 | 186 | 0 | 141444531 | ## https://codeforces.com/contest/321/problem/B
from bisect import bisect_right
def readline():
return list(map(int, input().split()))
def kill_all(ATK, DEF, attacking):
net_damage = 0
for def_ in sorted(DEF):
candidate = bisect_right(attacking, def_)
if candidate >= len(attacking):
... | 80 | 186 | 4,403,200 | 219942632 | from bisect import bisect_left, bisect_right, insort
from itertools import chain, repeat, starmap
from functools import reduce
from math import log
from operator import add, eq, ne, gt, ge, lt, le, iadd
from collections.abc import Sequence
class SortedList:
DEFAULT_LOAD_FACTOR = 1000
def __init__(self, itera... | Codeforces Round 190 (Div. 1) | CF | 2,013 | 2 | 256 | Ciel and Duel | Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following ope... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for... | Output an integer: the maximal damage Jiro can get. | null | In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage ... | [{"input": "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "output": "3000"}, {"input": "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "output": "992"}, {"input": "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "output": "1"}] | 1,900 | ["dp", "flows", "greedy"] | 80 | [{"input": "2 3\r\nATK 2000\r\nDEF 1700\r\n2500\r\n2500\r\n2500\r\n", "output": "3000\r\n"}, {"input": "3 4\r\nATK 10\r\nATK 100\r\nATK 1000\r\n1\r\n11\r\n101\r\n1001\r\n", "output": "992\r\n"}, {"input": "2 4\r\nDEF 0\r\nATK 0\r\n0\r\n0\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\nATK 100\r\n99\r\n", "output"... | false | stdio | null | true |
580/B | 580 | B | PyPy 3-64 | TESTS | 13 | 295 | 9,523,200 | 220908852 | n,k=map(int,input().split())
l=[]
l2=[]
for i in range(n):
a,b=map(int,input().split())
l.append([a,b])
l2.append([b,a])
l.sort()
m=0
s=l[0][1]
ma=0
for i in range(1,n):
if l[i][0]-l[m][0]<k and m!=i:
s+=l[i][1]
else:
while m!=i and m<n and l[i][0]-l[m][0]>=k and i>m:
m+=... | 35 | 389 | 15,155,200 | 217030633 | '''Sliding window'''
n, d = map(int, input().split())
f = [tuple(map(int, input().split())) for _ in range(n)]
f.sort()
p1, p2 = 0, 0
s = 0
m = 0
while p2!=n:
if f[p2][0]-f[p1][0] < d:
s+=f[p2][1]
p2+=1
m = max(m,s)
else:
s-=f[p1][1]
p1+=1
print(m) | Codeforces Round 321 (Div. 2) | CF | 2,015 | 2 | 256 | Kefa and Company | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to... | The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, $$1 \leq d \leq 10^9$$) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contai... | Print the maximum total friendship factir that can be reached. | null | In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends. | [{"input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100"}, {"input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111"}] | 1,500 | ["binary search", "sortings", "two pointers"] | 35 | [{"input": "4 5\r\n75 5\r\n0 100\r\n150 20\r\n75 1\r\n", "output": "100\r\n"}, {"input": "5 100\r\n0 7\r\n11 32\r\n99 10\r\n46 8\r\n87 54\r\n", "output": "111\r\n"}, {"input": "1 1000000000\r\n15 12\r\n", "output": "12\r\n"}, {"input": "5 1\r\n5 9\r\n2 10\r\n8 5\r\n18 12\r\n1 1\r\n", "output": "12\r\n"}, {"input": "3 3... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 224617423 | n, x = map(int,input().split())
k=0
for i in range(n):
c,d = input().split()
if c == '+':
x+=int(d)
elif x > int(d):
x-=int(d)
else:
k+=1
print(f"{x} {k}") | 34 | 31 | 0 | 195721279 | n,ice = map(int, input().split())
sad = 0
for i in range(n):
s, x = input().split()
x = int(x)
if s == "+":
ice = ice + x
elif s == "-":
if x <= ice:
ice = ice - x
else:
sad = sad + 1
print(ice, sad) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
686/A | 686 | A | Python 3 | TESTS | 7 | 31 | 0 | 206758140 | # // #include<stdio.h>
# // int main()
# // {
# // int n,x;
# // scanf("%d %d" , &n , &x);
# // int count = 0;
# // char sign;
# // int d;
# // for(int i = 0 ; i<n ; i++)
# // {
# // scanf("%c %d" , &sign , &d);
# // if(sign == '+') x += d;
# // else if(sign == '-' ... | 34 | 31 | 0 | 208813088 | n, x = map(int, input().split())
tot, d = x, 0
for i in range(n):
p = tuple(input().split())
if p[0] == '+':
tot += int(p[1])
else:
if tot >= int(p[1]):
tot -= int(p[1])
else:
d += 1
print(tot, d) | Codeforces Round 359 (Div. 2) | CF | 2,016 | 2 | 256 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q... | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | null | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Car... | [{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}] | 800 | ["constructive algorithms", "implementation"] | 34 | [{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\... | false | stdio | null | true |
441/B | 441 | B | Python 3 | TESTS | 9 | 109 | 307,200 | 78359522 | n,v=map(int,input().split())
L=[0]*3002
for i in range(n):
a,b=map(int,input().split())
L[a]+=b
fruit=0
for i in range(1,3001):
x=min(v,L[i-1])
L[i-1]-=x
y=min(v-x,L[i])
L[i]-=y
fruit+=(x+y)
print(fruit) | 51 | 77 | 2,969,600 | 167039024 | import sys
input = sys.stdin.readline
n, v = map(int, input().split())
d = [0]*3003
for i in range(n):
a, b = map(int, input().split())
d[a] += b
c = 0
y = 0
for i in range(1, 3002):
x = min(v, d[i])
c += x
d[i] -= max(y, x)
y = max(d[i], 0)
d[i+1] += y
print(c) | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
441/B | 441 | B | Python 3 | TESTS | 9 | 93 | 0 | 6865837 | # -*- coding: utf-8 -*-
import sys
f = sys.stdin
#f = open('H:\\Portable Python 3.2.5.1\\test_248B1.txt')
n, v = map(int, f.readline().strip().split())
p = [0]*3001
for i in range(n):
a, b = map(int, f.readline().strip().split())
p[a] += b
#print(p[:5])
S = 0
for k in range(1,len(p)):
dv = min(v,p[k... | 51 | 78 | 0 | 6848378 | n,v = [int(i) for i in input().split()]
f = 0
l = [0]*3002
for i in range(n):
a,b = [int(i) for i in input().split()]
l[a] += b
for i in range(1,3002):
pick = min(v,l[i-1])
l[i-1] -= pick
pick2 = min(v-pick,l[i])
l[i] -= pick2
f += pick + pick2
print(f) | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
441/B | 441 | B | PyPy 3-64 | TESTS | 9 | 124 | 5,529,600 | 209153575 | def main():
n, v = list(map(int, input().split()))
a = list()
d = {i:0 for i in range(3001)}
for i in range(n):
x, y = list(map(int, input().split()))
a.append([x, y])
d[x] += y
ost, ans = 0, 0
for i in range(1, 3001):
if v >= ost:
ans += ost
... | 51 | 78 | 102,400 | 6841272 | n, v = [int(c) for c in input().split()]
m = [[0, 0] for i in range(3003)]
for i in range(n):
a, b = [int(c) for c in input().split()]
m[a][1] += b
m[a+1][0] += b
res = 0
for i in range(1,3002):
if v <= m[i][0]:
res += v
else:
from_future = v - m[i][0]
got_fr = min(from... | Codeforces Round 252 (Div. 2) | CF | 2,014 | 1 | 256 | Valera and Fruits | Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,... | The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30... | Print a single integer — the maximum number of fruit that Valera can collect. | null | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sampl... | [{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}] | 1,400 | ["greedy", "implementation"] | 51 | [{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r... | false | stdio | null | true |
15/A | 15 | A | Python 3 | TESTS | 7 | 122 | 0 | 32554256 | n,t = map(int,input().split(' '))
mas = list()
t *= 2
suma = 2
for i in range(n):
x,a = map(int,input().split(' '))
mas.append(x*2-a)
mas.append(x*2+a)
sorted(mas)
for i in range(1,len(mas)//2):
ras = mas[i*2]-mas[i*2-1]
if ras>t:
suma += 2
elif ras==t:
suma += 1
print(suma) | 35 | 92 | 0 | 159989795 | n, t = [int(item) for item in input().split(' ')]
cont = []
for i in range(n):
center, hLen = [int(item) for item in input().split(' ')]
cont.append([center - hLen / 2, center + hLen / 2])
#print(cont)
ans = 2
cont.sort(key=lambda item: item[0])
for i in range(n - 1):
gap = cont[i + 1][0] - cont[i][1]
... | Codeforces Beta Round 15 | ICPC | 2,010 | 2 | 64 | Cottage Village | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Pe... | The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). | Output the amount of possible positions of the new house. | null | It is possible for the x-coordinate of the new house to have non-integer value. | [{"input": "2 2\n0 4\n6 2", "output": "4"}, {"input": "2 2\n0 4\n5 2", "output": "3"}, {"input": "2 3\n0 4\n5 2", "output": "2"}] | 1,200 | ["implementation", "sortings"] | 35 | [{"input": "2 2\r\n0 4\r\n6 2\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 4\r\n5 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n0 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n1 1\r\n", "output": "2\r\n"}, {"i... | false | stdio | null | true |
493/A | 493 | A | Python 3 | TESTS | 11 | 62 | 0 | 11827659 | s1 = input()
s2 = input()
n = int(input())
h = []
a = []
for i in range(n):
k = input().split()
if k[1] == 'h':
if (h.count(k[2]) == 0) and k[3]=='y':
h.append(k[2])
elif h.count(k[2]) == 1:
h.append(k[2])
print(s1,k[2],k[0])
if (h.count(k[2]) == 0) an... | 18 | 61 | 0 | 8959771 | teamname = []
teamname.append(input().strip())
teamname.append(input().strip())
n = int(input())
foul = [[0 for m in range(100)] for i in range(2)]
for i in range(n):
info = input().split()
t = int(info[0])
team = info[1]
m = int(info[2])
card = info[3]
if team=='h': td = 0
else: td = 1
... | Codeforces Round 281 (Div. 2) | CF | 2,014 | 2 | 256 | Vasya and Football | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1 ≤ n ≤ 90) — the... | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs;
- the player's number in his team;
- the minute when he received the card.
If no player received a card, then you do not need to pr... | null | null | [{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}] | 1,300 | ["implementation"] | 18 | [{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\... | false | stdio | null | true |
650/B | 650 | B | PyPy 3 | TESTS | 34 | 327 | 31,846,400 | 86483515 | import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
"""
Facts and Data representation
Constructive? Top bottom up down
"""
n, a, b, T = I... | 41 | 873 | 8,499,200 | 101064635 | # [https://codeforces.com/contest/650/submission/16709913]
(n, a, b, t) = map(int, input().split())
b += 1
l = [b if char == "w" else 1 for char in input()]
t -= sum(l) - a * (n + 2)
hi = n
n2 = n * 2
n3 = n2 + 1
lo = 0
res = 0
l *= 2
while lo <= n and hi < n2:
t -= l[hi]
hi += 1
while (hi - lo + (hi if hi... | Codeforces Round 345 (Div. 1) | CF | 2,016 | 1 | 256 | Image Preview | Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec... | The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·105, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.
Second line of the input contains a string of length n containing sy... | Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds. | null | In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.
Note that in the last sample test the time is not enough even to watch the first phot... | [{"input": "4 2 3 10\nwwhw", "output": "2"}, {"input": "5 2 4 13\nhhwhh", "output": "4"}, {"input": "5 2 4 1000\nhhwhh", "output": "5"}, {"input": "3 1 100 10\nwhw", "output": "0"}] | 1,900 | ["binary search", "brute force", "dp", "two pointers"] | 41 | [{"input": "4 2 3 10\r\nwwhw\r\n", "output": "2\r\n"}, {"input": "5 2 4 13\r\nhhwhh\r\n", "output": "4\r\n"}, {"input": "5 2 4 1000\r\nhhwhh\r\n", "output": "5\r\n"}, {"input": "3 1 100 10\r\nwhw\r\n", "output": "0\r\n"}, {"input": "10 2 3 32\r\nhhwwhwhwwh\r\n", "output": "7\r\n"}, {"input": "1 2 3 3\r\nw\r\n", "output... | false | stdio | null | true |
962/F | 962 | F | PyPy 3-64 | TESTS | 4 | 46 | 0 | 185924253 | from sys import stdin
input=lambda :stdin.readline()[:-1]
def scc(N,edges):
M=len(edges)
start=[0]*(N+1)
elist=[0]*M
for e in edges:
start[e[0]+1]+=1
for i in range(1,N+1):
start[i]+=start[i-1]
counter=start[:]
for e in edges:
elist[counter[e[0]]]=e[1]
counte... | 42 | 857 | 40,243,200 | 129765854 | import sys
def solve():
n, m = map(int, input().split())
g = [[] for i in range(n+1)]
E = [None]*m
for i in range(m):
u, v = map(int, input().split())
E[i] = (u, v)
g[u].append([v,i])
g[v].append([u,i])
P = [-1]*(n+1)
I = [0]*(n+1)
st = []
D = [0]*(n+1)
W = [0]*(n+1)
S = [-1]*m
U = [-1]*m
V = [-1]*... | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Simple Cycles Edges | You are given an undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself).
A cycle in a graph is called a simple, if ... | The first line contain two integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 100\,000$$$, $$$0 \le m \le \min(n \cdot (n - 1) / 2, 100\,000))$$$ — the number of vertices and the number of edges.
Each of the following $$$m$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the descr... | In the first line print the number of edges, which belong to exactly one simple cycle.
In the second line print the indices of edges, which belong to exactly one simple cycle, in increasing order. The edges are numbered from one in the same order as they are given in the input. | null | null | [{"input": "3 3\n1 2\n2 3\n3 1", "output": "3\n1 2 3"}, {"input": "6 7\n2 3\n3 4\n4 2\n1 2\n1 5\n5 6\n6 1", "output": "6\n1 2 3 5 6 7"}, {"input": "5 6\n1 2\n2 3\n2 4\n4 3\n2 5\n5 3", "output": "0"}] | 2,400 | ["dfs and similar", "graphs", "trees"] | 42 | [{"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "6 7\r\n2 3\r\n3 4\r\n4 2\r\n1 2\r\n1 5\r\n5 6\r\n6 1\r\n", "output": "6\r\n1 2 3 5 6 7 \r\n"}, {"input": "5 6\r\n1 2\r\n2 3\r\n2 4\r\n4 3\r\n2 5\r\n5 3\r\n", "output": "0\r\n\r\n"}, {"input": "4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 1\r\n1 3\r\n"... | false | stdio | null | true |
15/A | 15 | A | Python 3 | TESTS | 7 | 92 | 0 | 220924159 | n, t = map(int, input().split())
center, length = map(int, input().split())
spots = 2
for i in range(n-1):
bottom = center + length/2
center, length = map(int, input().split())
top = center - length/2
if (top - bottom) > t:
spots = spots + 2
elif (top - bottom) == t:
spots += 1
prin... | 35 | 92 | 0 | 161627169 | import sys
input = sys.stdin.readline
n, t = map(int, input().split())
d = []
for i in range(n):
x, a = map(int, input().split())
d.append(x-a/2)
d.append(x+a/2)
d.sort()
c = 2
for i in range(1, 2*n-1, 2):
if d[i+1] - d[i] > t:
c += 2
elif d[i+1] - d[i] == t:
c += 1
print(c) | Codeforces Beta Round 15 | ICPC | 2,010 | 2 | 64 | Cottage Village | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Pe... | The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). | Output the amount of possible positions of the new house. | null | It is possible for the x-coordinate of the new house to have non-integer value. | [{"input": "2 2\n0 4\n6 2", "output": "4"}, {"input": "2 2\n0 4\n5 2", "output": "3"}, {"input": "2 3\n0 4\n5 2", "output": "2"}] | 1,200 | ["implementation", "sortings"] | 35 | [{"input": "2 2\r\n0 4\r\n6 2\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 4\r\n5 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n0 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n1 1\r\n", "output": "2\r\n"}, {"i... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.