input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
n = int(eval(input()))
nodes = []
id_list = []
output = [None for i in range(n)]
cnt = 0
root = set(range(n))
for i in range(n):
id, _, *li = list(map(int, input().split(' ')))
root -= set(li)
nodes.append(li)
id_list.append(id)
def rooted_tree(id, depth, parent):
out = {}
ind = id_list.index(id)
out['node'] = id
out['parent'] = parent
out['depth'] = depth
out['c'] = nodes[ind]
if depth == 0:
out['type'] = 'root'
elif len(nodes[ind]) == 0:
out['type'] = 'leaf'
else:
out['type'] = 'internal node'
output[id] = out
for i in (nodes[ind]):
rooted_tree(i, depth+1, id)
rooted_tree(root.pop(), 0, -1)
for line in output:
print(("node {}: parent = {}, depth = {}, {}, {}".format(line['node'], line['parent'], line['depth'], line['type'], line['c'])))
|
n = int(eval(input()))
nodes = [0 for i in range(n)]
output = [None for i in range(n)]
cnt = 0
root = set(range(n))
for i in range(n):
id, _, *li = list(map(int, input().split(' ')))
root -= set(li)
nodes[id] = li
def rooted_tree(id, depth, parent):
out = {}
out['node'] = id
out['parent'] = parent
out['depth'] = depth
out['c'] = nodes[id]
if depth == 0:
out['type'] = 'root'
elif len(nodes[id]) == 0:
out['type'] = 'leaf'
else:
out['type'] = 'internal node'
output[id] = out
for i in (nodes[id]):
rooted_tree(i, depth+1, id)
rooted_tree(root.pop(), 0, -1)
for line in output:
print(("node {}: parent = {}, depth = {}, {}, {}".format(line['node'], line['parent'], line['depth'], line['type'], line['c'])))
|
p02279
|
#coding:utf-8
#1_7_A
class Node():
def __init__(self, node_id, degree, children):
self.node_id = node_id
self.parent = -1
self.depth = 0
self.typ = "leaf"
self.degree = degree
self.children = children
def set_attr(self, parent, depth):
self.parent = parent
self.depth = depth
for child_id in self.children:
self.typ = "internal node"
tree[child_id].set_attr(self.node_id, self.depth + 1)
if self.parent == -1:
self.typ = "root"
n = int(eval(input()))
tree = [None for i in range(n)]
root = set(range(n))
for i in range(n):
info = list(map(int, input().split()))
tree[info[0]] = Node(info[0], info[1], info[2:])
root -= set(info[2:])
root_id = root.pop()
tree[root_id].set_attr(-1, 0)
for node in tree:
print(("node {}: parent = {}, depth = {}, {}, {}".format(node.node_id, node.parent, node.depth, node.typ, node.children)))
|
#coding:utf-8
#1_7_A
class Node():
def __init__(self, node_id, children):
self.node_id = node_id
self.parent = -1
self.depth = 0
self.typ = "leaf"
self.children = children
def set_attr(self, parent, depth):
self.parent = parent
self.depth = depth
for child_id in self.children:
self.typ = "internal node"
tree[child_id].set_attr(self.node_id, self.depth + 1)
if self.parent == -1:
self.typ = "root"
n = int(eval(input()))
tree = [None for i in range(n)]
root = set(range(n))
for i in range(n):
info = list(map(int, input().split()))
tree[info[0]] = Node(info[0], info[2:])
root -= set(info[2:])
root_id = root.pop()
tree[root_id].set_attr(-1, 0)
for node in tree:
print(("node {}: parent = {}, depth = {}, {}, {}".format(node.node_id, node.parent, node.depth, node.typ, node.children)))
|
p02279
|
# -*- coding:utf-8 -*-
import sys
from collections import OrderedDict
def cleate_node_dict(children):
node_dict = OrderedDict()
for val in children:
node_dict[val] = OrderedDict()
return node_dict
def cleate_tree(nodes):
tree = nodes.copy()
for node, children in list(nodes.items()):
for key in list(children.keys()):
children[key] = nodes[key]
del tree[key]
return tree
def rec(current, acc, parent=-1, depth=0):
if current == {}:
return
for node, children in list(current.items()):
cld_lst = list(children.keys())
acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format(
node, parent, depth, node_type(parent, children), cld_lst)
rec(children, acc, node, depth+1)
def node_type(parent, children):
if parent == -1:
return "root"
elif children != {}:
return "internal node"
else:
return "leaf"
if __name__ == "__main__":
n = int(eval(input()))
lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()]
nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst}
tree = cleate_tree(nodes)
node_info = {}
rec(tree, node_info)
for key, val in sorted(node_info.items()):
print(val)
|
# -*- coding:utf-8 -*-
import sys
from collections import OrderedDict
def cleate_node_dict(children):
node_dict = OrderedDict()
for val in children:
node_dict[val] = None
return node_dict
def cleate_tree(nodes):
tree = nodes.copy()
for node, children in list(nodes.items()):
for key in list(children.keys()):
children[key] = nodes[key]
del tree[key]
return tree
def rec(current, acc, parent=-1, depth=0):
if current == {}:
return
for node, children in list(current.items()):
cld_lst = list(children.keys())
acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format(
node, parent, depth, node_type(parent, children), cld_lst)
rec(children, acc, node, depth+1)
def node_type(parent, children):
if parent == -1:
return "root"
elif children != {}:
return "internal node"
else:
return "leaf"
def rooted_trees(lst, n):
nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst}
tree = cleate_tree(nodes)
node_info = [None] * n
rec(tree, node_info)
print(("\n".join(node_info)))
if __name__ == "__main__":
n = int(eval(input()))
lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()]
rooted_trees(lst, n)
|
p02279
|
a,b,c = list(map(int, input().split()))
if a == max(a,b,c):
print((int(b*c / 2)))
elif b == max(a,b,c):
print((int(a*c / 2)))
elif c == max(a,b,c):
print((int(a*b / 2)))
|
a, b, c = list(map(int, input().split()))
print((a*b // 2))
|
p03145
|
a,b,c = sorted([int(i) for i in input().split()])
print((int(a*b/2)))
|
a = [int(i) for i in input().split()]
a = sorted(a)
ans = int(a[0] * a[1]/2)
print(ans)
|
p03145
|
a,b,c = list(map(int,input().split()))
if a**2+b**2==c**2:
ans = a*b//2
elif a**2+c**2==b**2:
ans = a*c//2
else:
ans = b*c//2
print(ans)
|
a,b,c = list(map(int,input().split()))
print((a*b//2))
|
p03145
|
a,b,c = list(map(int,input().split()))
print((a*b//2))
|
a,b,c = sorted(map(int,input().split()))
print((a*b//2))
|
p03145
|
print(((lambda l:l[0]*l[1]//2)(sorted(list(map(int,input().split()))))))
|
print(((lambda l:l[0]*l[1]//2)(list(map(int,input().split())))))
|
p03145
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
AB, BC, CA = [int(x.strip("|")) for x in input().split()]
print((int(AB*BC/2)))
|
えーびー,びーしー,_ = list(map(int,input().split()))
めんせき =えーびー*びーしー//2
print(めんせき)
|
p03145
|
X = list(map(int,input().split()))
X.sort()
print((X[0]*X[1]//2))
|
AB,BC,CA = list(map(int,input().split()))
print((AB*BC//2))
|
p03145
|
def main():
a, b, c = (int(i) for i in input().split())
from math import sqrt
s = (a + b + c) / 2
print((int(sqrt(s*(s-a)*(s-b)*(s-c)))))
if __name__ == '__main__':
main()
|
def main():
a, b, c = (int(i) for i in input().split())
print((a*b//2))
if __name__ == '__main__':
main()
|
p03145
|
# -*- coding: utf-8 -*-
a, b, c = list(map(int, input().split()))
print((int(a*b/2)))
|
A, B, C = list(map(int, input().split()))
print(((A * B) // 2))
|
p03145
|
a = list(map(int,input().split()))
a.sort()
print((int(a[0]*a[1]/2)))
|
l = list(map(int,input().split()))
l.sort()
print((int(l[0]*l[1]/2)))
|
p03145
|
# coding: utf-8
from sys import stdin
AB,BC,AC = list(map(int, stdin.readline().rstrip().split()))
print((int(AB*BC/2)))
|
# coding: utf-8
AB,BC,AC = list(map(int, input().split()))
print((AB*BC//2))
|
p03145
|
AB, BC, CA = list(map(int, input().split()))
print((AB * BC//2))
|
A, B, C = list(map(int, input().split()))
print((A * B // 2))
|
p03145
|
A, B, C =list(map(int,input().split()))
print(((A*B)//2))
|
a,b,c = list(map(int,input().split()))
print((int((1/2)*a*b)))
|
p03145
|
a,b,c = list(map(int,input().split()))
print((int(a*b/2)))
|
a,b,c = list(map(int,input().split()))
print((a*b//2))
|
p03145
|
a,b,c = list(map(int,input().split()))
print(((a*b)//2))
|
L = sorted(list(map(int,input().split())))
print(((L[0]*L[1])//2))
|
p03145
|
import itertools
import math
import fractions
import functools
import copy
ab, bc, ca = list(map(int, input().split()))
print((ab*bc//2))
|
def main():
# n = int(input())
a, b, c = list(map(int, input().split()))
# h = list(map(int, input().split()))
# s = input()
print((a*b//2))
if __name__ == '__main__':
main()
|
p03145
|
AB,BC,CA = list(map(int,input().split()))
print((AB*BC//2))
|
a,b,c=list(map(int,input().split()))
print((a*b//2))
|
p03145
|
a, b, c = list(map(int, input().split()))
print((int(a*b/2)))
|
a, b, c = list(map(int, input().split()))
ans = a * b // 2
print(ans)
|
p03145
|
a,b,c = list(map(int, input().split()))
print((a*b//2))
|
AB,BC,CA = list(map(int,input().split()))
print((AB*BC//2))
|
p03145
|
a,b,c=list(map(int,input().split()))
s=int((a*b)/2)
print(s)
|
a,b,c=list(map(int,input().split()))
print((int(a*b/2)))
|
p03145
|
A, B, C = sorted(map(int,input().split()))
print((int((A*B)/2)))
|
A, B, C = list(map(int,input().split()))
print((A*B//2))
|
p03145
|
a, b, c = list(map(int,input().split()))
print(((a*b)//2))
|
def ans():
A, B, C = list(map(int,input().split()))
print(((A*B)//2))
ans()
|
p03145
|
import math
V = [int(n) for n in input().split()]
s = sum(V) / 2
A = math.sqrt(s*(s-V[0])*(s-V[1])*(s-V[2]))
print((int(A)))
|
a, b, c = list(map(int, input().split()))
print((a * b // 2))
|
p03145
|
a = list(map(int,input().split()))
a.sort()
print((a[0]*a[1]//2))
|
R= list(map(int,input().split()))
R.sort()
print((R[0] * R[1] // 2))
|
p03145
|
a, b, c = list(map(int, input().split()))
print((int(a * b * 0.5)))
|
a, b, c = list(map(int, input().split()))
print((a * b // 2))
|
p03145
|
ab,bc,ca=input().split()
ab,bc,ca=int(ab),int(bc),int(ca)
print((ab*bc//2))
|
a,b,_=list(map(int,input().split()))
print((a*b//2))
|
p03145
|
import math
a,b,c=sorted(map(int,input().split()))
print((math.floor(a*b/2)))
|
x, y, z = sorted(map(int, input().split()))
print(((x * y) // 2))
|
p03145
|
import sys
from collections import defaultdict as dd
from collections import deque as dq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
if K >= N - 1:
print((int(a[0] != 1)))
exit(0)
res = 0
if a[0] != 1:
a[0] = 1
res += 1
e = dd(set)
for i in range(N):
e[a[i]].add(i + 1)
#print(e)
Q = dq([1])
d = [float("inf")] * (N + 1)
d[1] = 0
while len(Q):
p = Q.popleft()
for q in e[p]:
if d[q] > d[p] + 1:
d[q] = d[p] + 1
Q.append(q)
#print(d)
eulbase = pow(10, 6)
euler = []
depth = [0] * (N + 1)
table = [0] * (N + 1)
def eulerdfs(x, d):
global euler
global depth
global table
table[x] = len(euler)
depth[x] = d
euler.append(d * eulbase + x)
for y in e[x]:
if x == y: continue
eulerdfs(y, d + 1)
euler.append(d * eulbase + x)
for i in range(len(euler) - 1, -1, -1): table[euler[i] % eulbase] = i
eulerdfs(1, 0)
#print(euler)
#print(table)
class minSegTree:
def segfunc(self, x, y):
return min(x, y)
def __init__(self, n, ide_ele, init_val):
#####単位元######
self.ide_ele = ide_ele
#num:n以上の最小の2のべき乗
self.num = 2 ** (n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
#set_val
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
#built
for i in range(self.num - 2, -1, -1) :
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
class maxSegTree:
def segfunc(self, x, y):
return max(x, y)
def __init__(self, n, ide_ele, init_val):
#####単位元######
self.ide_ele = ide_ele
#num:n以上の最小の2のべき乗
self.num = 2 ** (n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
#set_val
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
#built
for i in range(self.num - 2, -1, -1) :
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
euler.pop()
minseg = minSegTree(len(euler), N * eulbase, euler)
maxseg = maxSegTree(len(euler), 0, euler)
#print(euler)
ex = dd(list)
for i in range(len(euler)):
ok = i + 1
ng = len(euler) + 1
while ng - ok > 1:
m = (ok + ng) // 2
if (maxseg.query(i, m) // eulbase) - (minseg.query(i, m) // eulbase) <= K: ok = m
else: ng = m
ex[i].append((ok, 1))
for i in range(len(euler), 0, -1):
ex[i].append((i - 1, 0))
#print(ex)
import heapq
class dijkstra:
def __init__(self, n, e):
self.e = e
self.n = n
def path(self, s, t):
d = [float("inf")] * (self.n + 1)
vis = set()
d[s] = 0
h = [s]
while not t in vis and len(h):
v = heapq.heappop(h)
v1 = v % (10 ** 6)
v0 = v // (10 ** 6)
if v1 in vis: continue
vis.add(v1)
for p in self.e[v1]:
d[p[0]] = min(d[p[0]], d[v1] + p[1])
if p[0] in vis: continue
heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
return d[t]
dij = dijkstra(len(euler), ex)
print((dij.path(0, len(euler)) - 1 + res))
|
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
if K >= N - 1:
print((int(a[0] != 1)))
exit(0)
res = 0
if a[0] != 1:
a[0] = 1
res += 1
e = dd(set)
inc = [0] * (N + 1)
for i in range(N):
if i + 1 == a[i]: continue
e[a[i]].add(i + 1)
inc[a[i]] += 1
t = set()
def dfs(x):
global res
d = 0
for y in e[x]:
d = max(d, dfs(y) + 1)
if d == K - 1:
res += (a[x - 1] != 1)
return -1
return d
dfs(1)
print(res)
|
p04008
|
from heapq import heappop,heappush
n,k = list(map(int,input().split()))
a = [0] + list(map(int,input().split()))
ans = 0
if(a[1] != 1):
ans += 1
links_c = [set() for _ in range(n+1)]
for i,ai in enumerate(a[2:],2):
links_c[ai].add(i)
depth = [-1] * (n+1)
depth[1] = 0
stack = [1]
hq = []
while(stack):
next = []
while(stack):
i = stack.pop()
for j in links_c[i]:
depth[j] = depth[i] + 1
heappush(hq, (depth[j]*-1,j))
next.append(j)
stack = next[::]
while( hq[0][0]*-1 > k ):
di,i = heappop(hq)
if( depth[i] <= k ):
continue
for j in range(k-1):
i = a[i]
ans += 1
links_c[a[i]].remove(i)
stack = [i]
while(stack):
next = []
while(stack):
i = stack.pop()
depth[i] = 1
for j in links_c[i]:
next.append(j)
stack = next[::]
print(ans)
'''
首都の自己ループを除くと、首都を根として、
子→親の有向木になっている。
・首都のテレポート先は首都でないとダメ
→ 長さ2以上の閉路を作るとうまくいかない
・首都以外は、首都までの距離をk以下にできればよい
もっとも根からの距離が遠い頂点xをとる。
xが根からの距離k以下 → 終了してOK
xが根からの距離k以上
→ xからk-1個離れた親を首都につなぎなおす
そして再度最も遠い頂点を探す、を繰り返す。
'''
|
n,k = list(map(int,input().split()))
a = [0] + list(map(int,input().split()))
ans = 0
if(a[1] != 1):
ans += 1
links_c = [set() for _ in range(n+1)]
for i,ai in enumerate(a[2:],2):
links_c[ai].add(i)
depth = [-1] * (n+1)
depth[1] = 0
stack = [1]
ts = [(0,1)]
while(stack):
next = []
while(stack):
i = stack.pop()
for j in links_c[i]:
depth[j] = depth[i] + 1
ts.append((depth[j],j))
next.append(j)
stack = next[::]
while( ts[-1][0] > k ):
di,i = ts.pop()
if( depth[i] <= k ):
continue
for j in range(k-1):
i = a[i]
ans += 1
links_c[a[i]].remove(i)
stack = [i]
while(stack):
next = []
while(stack):
i = stack.pop()
depth[i] = 1
for j in links_c[i]:
next.append(j)
stack = next[::]
print(ans)
|
p04008
|
import sys
sys.setrecursionlimit(200000)
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
if a[0] != 1:
a[0] = 1
ans += 1
b = [[]for i in range(n)]
for i in range(n):
b[a[i]-1].append(i)
b[0].remove(0)
huka = 0
kyo = [float("inf")] * n
z =[[]for i in range(n)]
def dfs(x,y):
kyo[x] = y
z[y].append(x)
for i in b[x]:
dfs(i,y+1)
dfs(0,0)
def dfs2(x,y):
if kyo[x] <=k-y:
return
if y == k-1 and x != 0:
kyo[x] = 0
global ans
ans += 1
return
kyo[x] = 0
dfs2(a[x]-1,y+1)
for i in range(n-1,k,-1):
for j in z[i]:
dfs2(j,0)
print(ans)
|
import sys
sys.setrecursionlimit(200000)
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
if a[0] != 1:
a[0] = 1
ans += 1
b = [[]for i in range(n)]
for i in range(1,n):
b[a[i]-1].append(i)
huka = 0
kyo = [float("inf")] * n
z =[[]for i in range(n)]
def dfs(x,y):
kyo[x] = y
z[y].append(x)
for i in b[x]:
dfs(i,y+1)
dfs(0,0)
def dfs2(x,y):
if kyo[x] <=k-y:
return
if y == k-1 and x != 0:
kyo[x] = 0
global ans
ans += 1
return
kyo[x] = 0
dfs2(a[x]-1,y+1)
for i in range(n-1,k,-1):
for j in z[i]:
dfs2(j,0)
print(ans)
|
p04008
|
def DFS(graph,root,parent):
dist = [-1]*(n+1)
dist[root] = 0
stack = [root]
while stack:
x = stack.pop()
for y in graph[x]:
if dist[y] == -1:
parent[y] = x
dist[y] = dist[x]+1
stack.append(y)
return dist
#親のリスト、頂点v、kが与えられたときに「vのk個上の祖先」を見る
class Doubling:
def __init__(self,graph,root):
self.root = root
n = len(graph)-1
self.ancestor_ls = [[0]*(n+1)]
self.distance = DFS(graph,root,self.ancestor_ls[0])
self.bitn = n.bit_length()
for i in range(1,self.bitn+1):
ancestor_ls_app = [0]*(n+1)
for j in range(1,n+1):
ancestor_ls_app[j] = self.ancestor_ls[i-1][self.ancestor_ls[i-1][j]]
self.ancestor_ls.append(ancestor_ls_app)
def dist(self):
return self.distance
def parent(self):
return self.ancestor_ls[0]
def ancestor(self,v,depth):
if depth == 1:
return self.ancestor_ls[0][v]
if depth == 2:
return self.ancestor_ls[1][v]
if depth == 0:
return v
if n<depth:
return self.root
ret = v
for i in range(self.bitn):
if depth&1<<i:
ret = self.ancestor_ls[i][ret]
return ret
import sys
input = sys.stdin.readline
from collections import deque
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
if a[0] != 1:
ans += 1
graph = [[] for i in range(n+1)]
for i in range(1,n):
graph[a[i]].append(i+1)
graph[i+1].append(a[i])
if k > n:
print(ans)
exit()
sol = Doubling(graph,1)
dist = sol.dist()
if k == 1:
print((n-dist.count(1)-dist.count(0)+ans))
exit()
dls = []
for i in range(1,n+1):
dls.append((dist[i],i))
vis = [0]*(n+1)
dls.sort()
dlsq = deque(dls)
parent = sol.parent()
while True:
d,x = dlsq.pop()
if d <= k:
break
if vis[x] == 1:
continue
ans += 1
anc = sol.ancestor(x,k-1)
stack = deque([anc])
while stack:
v = stack.pop()
vis[v] = 1
for u in graph[v]:
if parent[u] == v:
stack.append(u)
print(ans)
|
def DFS(graph,root,parent):
dist = [-1]*(n+1)
dist[root] = 0
stack = [root]
while stack:
x = stack.pop()
for y in graph[x]:
if dist[y] == -1:
parent[y] = x
dist[y] = dist[x]+1
stack.append(y)
return dist
#親のリスト、頂点v、kが与えられたときに「vのk個上の祖先」を見る
class Doubling:
def __init__(self,graph,root):
self.root = root
n = len(graph)-1
self.ancestor_ls = [[0]*(n+1)]
self.distance = DFS(graph,root,self.ancestor_ls[0])
self.bitn = n.bit_length()
for i in range(1,self.bitn+1):
ancestor_ls_app = [0]*(n+1)
for j in range(1,n+1):
ancestor_ls_app[j] = self.ancestor_ls[i-1][self.ancestor_ls[i-1][j]]
self.ancestor_ls.append(ancestor_ls_app)
def dist(self):
return self.distance
def parent(self):
return self.ancestor_ls[0]
def ancestor(self,v,depth):
if depth == 1:
return self.ancestor_ls[0][v]
if depth == 2:
return self.ancestor_ls[1][v]
if depth == 0:
return v
if n<depth:
return self.root
ret = v
for i in range(self.bitn):
if depth&1<<i:
ret = self.ancestor_ls[i][ret]
return ret
import sys
input = sys.stdin.readline
from collections import deque
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
if a[0] != 1:
ans += 1
graph = [[] for i in range(n+1)]
for i in range(1,n):
graph[a[i]].append(i+1)
graph[i+1].append(a[i])
if k > n:
print(ans)
exit()
sol = Doubling(graph,1)
dist = sol.dist()
if k == 1:
print((n-dist.count(1)-dist.count(0)+ans))
exit()
dls = []
for i in range(1,n+1):
dls.append((dist[i],i))
vis = [0]*(n+1)
dls.sort()
dlsq = deque(dls)
parent = sol.parent()
while True:
d,x = dlsq.pop()
if d <= k:
break
if vis[x] == 1:
continue
ans += 1
anc = sol.ancestor(x,k-1)
stack = deque([anc])
while stack:
v = stack.pop()
vis[v] = 1
for u in graph[v]:
if parent[u] == v and vis[u] != 1:
stack.append(u)
print(ans)
|
p04008
|
# ABC135
def main():
a, b = tuple(map(int, input().rstrip().split()))
print(((a + b) // 2 if (a + b) % 2 == 0 else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
|
# ABC135A - Harmony
def main():
A, B = list(map(int, input().split()))
flg = (A + B) % 2 == 0
print(((A + B) // 2 if flg else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
|
p02957
|
a, b = list(map(int, input().split()))
k = ( a + b )
if k%2 == 0:
print((k//2))
else:
print('IMPOSSIBLE')
|
a, b = list(map(int, input().split()))
if (a**2 - b**2) % (2 * (a - b)) == 0:
print(((a**2 - b**2) // (2 * (a - b))))
else:
print('IMPOSSIBLE')
|
p02957
|
ab = input().split()
A, B = int(ab[0]), int(ab[1])
if A == B:
print((1))
elif A % 2 != B % 2:
print("IMPOSSIBLE")
else:
K = (A+B) // 2
if abs(A-K) == abs(B-K):
print(K)
else:
print("IMPOSSIBLE")
|
ab = input().split()
A, B = int(ab[0]), int(ab[1])
out = None
if A == B:
out = None
elif A % 2 != B % 2:
out = "IMPOSSIBLE"
else:
K = (A+B) // 2
if abs(A-K) == abs(B-K):
out = K
else:
out = "IMPOSSIBLE"
print(out)
|
p02957
|
a,b=list(map(int,input().split()))
if (a+b)%2==0:
print(((a+b)//2))
else:
print("IMPOSSIBLE")
|
a,b=list(map(int,input().split()))
if (a+b)%2!=0:
print("IMPOSSIBLE")
else:
print(((a+b)//2))
|
p02957
|
a, b = list(map(int, input().split()))
if abs(b - a) % 2:
print('IMPOSSIBLE')
else:
print((abs(b - a) // 2 + min(a, b)))
|
a, b = list(map(int, input().split()))
if (a - b) % 2 == 0:
print(((a + b) // 2))
else:
print('IMPOSSIBLE')
|
p02957
|
a, b = list(map(int, input().split()))
if (a - b) % 2 == 0:
print(((a + b) // 2))
else:
print("IMPOSSIBLE")
|
a, b = list(map(int, input().split()))
print(((a+b)// 2 if (a+b)% 2 == 0 else "IMPOSSIBLE"))
|
p02957
|
a,b = list(map(int,input().split()))
if a%2==0 and b%2!=0:
print("IMPOSSIBLE")
elif a%2!=0 and b%2==0:
print("IMPOSSIBLE")
else:
print((int(((a+b)/2))))
|
a,b = list(map(int,input().split()))
if (a%2) != (b%2):
print("IMPOSSIBLE")
else:
print((int(((a+b)/2))))
|
p02957
|
A,B = list(map(int, input().split()))
a=(A+B)
if (a)%2==1:
print('IMPOSSIBLE')
else:
print((str(int(a/2))))
|
A,B = list(map(int, input().split()))
if (A+B)%2==1:
print('IMPOSSIBLE')
else:
print((int((A+B)/2)))
|
p02957
|
#ABC135A - Harmony
A, B = list(map(int,input().split()))
if (max(A,B) - min(A,B)) % 2 == 1:
print("IMPOSSIBLE")
else:
print(((A+B)//2))
|
#ABC135A - Harmony
A, B = list(map(int,input().split()))
if (A+B) % 2 == 1:
print("IMPOSSIBLE")
else:
print(((A+B)//2))
|
p02957
|
a,b=list(map(int,input().split()))
k=(a+b)/2
if int(k)<(a+b)/2:
print('IMPOSSIBLE')
else:
print((int(k)))
|
A, B = list(map(int, input().split()))
print(((A+B)//2 if (A+B) % 2 == 0 else "IMPOSSIBLE"))
|
p02957
|
s=eval(input().replace(" ","+"))
print((s//2 if s%2==0 else "IMPOSSIBLE"))
|
A, B = list(map(int, input().split()))
print(((A+B)//2 if (A+B) % 2 == 0 else "IMPOSSIBLE"))
|
p02957
|
# coding: utf-8
# Your code here!
A,B=input().split()
A=int(A)
B=int(B)
def abs(x):
if x>=0:
return x
else:
return -x
if abs(A-B)%2==0:
print((min(A,B)+int(abs(A-B)/2)))
else:
print('IMPOSSIBLE')
|
A, B = list(map(int, input().split()))
if (A + B) % 2 == 0:
K = (A + B) // 2
print(K)
else:
print('IMPOSSIBLE')
|
p02957
|
A,B = list(map(int,input().split()))
if (A+B)%2==0:
print(((A+B)//2))
else:
print("IMPOSSIBLE")
|
A,B = list(map(int,input().split()))
if A>B:
A,B = B,A
if (B-A)%2==0:
print(((B+A)//2))
else:
print("IMPOSSIBLE")
|
p02957
|
a, b = list(map(int, input().split()))
large = max(a, b)
ans = 0
for i in range((a+b)//2, large):
if abs(a - i) == abs(b - i):
ans = i
break
if ans == 0:
print("IMPOSSIBLE")
else:
print(ans)
|
a, b = list(map(int, input().split()))
large = max(a, b)
ans = ((a + b) / 2)
if ans.is_integer():
print((int(ans)))
else:
print("IMPOSSIBLE")
|
p02957
|
a=eval(input().replace(' ','+'));print((a%2*'IMPOSSIBLE'or a//2))
|
a=eval(input().replace(*' +'))
print((a%2*'IMPOSSIBLE'or a//2))
|
p02957
|
a, b = list(map(int, input().split()))
if (a+b) % 2 == 0:
print(((a + b) // 2))
else:
print("IMPOSSIBLE")
|
a, b = list(map(int, input().split()))
if abs(a-b) % 2 == 0:
print(((a+b)//2))
else:
print("IMPOSSIBLE")
|
p02957
|
A, B = list(map(int, input().split()))
if (A+B) % 2 == 0:
print(((A+B)//2))
else:
print("IMPOSSIBLE")
|
def LI():
return list(map(int, input().split()))
A, B = LI()
if (A+B) % 2 == 0:
ans = (A+B)//2
else:
ans = "IMPOSSIBLE"
print(ans)
|
p02957
|
A,B=list(map(int, input().split()))
print(((A+B)//2 if (A+B)&1==0 else 'IMPOSSIBLE'))
|
A, B = list(map(int, input().split()))
if A > B: A, B = B, A
if (B - A) & 1:
print('IMPOSSIBLE')
exit()
print((A + (B - A) // 2))
|
p02957
|
A, B = list(map(int, input().split()))
if (A+B) % 2:
print('IMPOSSIBLE')
else:
print(((A+B)//2))
|
a=eval(input().replace(' ','+'));print((a%2*'IMPOSSIBLE'or a//2))
|
p02957
|
a, b = list(map(int, input().split()))
if (a+b)%2 != 0:
print("IMPOSSIBLE")
else:
print(((a+b)//2))
|
a, b = list(map(int, input().split()))
if (a+b)%2 != 0:
print("IMPOSSIBLE")
else:
print((int((a+b)/2)))
|
p02957
|
from functools import reduce
n, _, c = list(map(int, input().split()))
bs = tuple(map(int, input().split()))
count = 0
for i in range(n):
if reduce(
lambda x, y: x + y[0] * y[1],
list(zip(bs, list(map(int, input().split())))),
0,
) + c > 0:
count += 1
print(count)
|
n, _, c = list(map(int, input().split()))
bs = tuple(map(int, input().split()))
count = 0
for _ in range(n):
if sum(x * bs[i] for i, x in enumerate(map(int, input().split()))) + c > 0:
count += 1
print(count)
|
p03102
|
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for _ in range(n):
a = list(map(int, input().split()))
t = 0
for i in range(m):
t += a[i]*b[i]
if (t + c) > 0:
ans += 1
print(ans)
|
# ソースコードの正答を判定する。
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for _ in range(n):
a = list(map(int, input().split()))
t = 0
for i in range(m):
t += a[i]*b[i]
if (t + c) > 0:
ans += 1
print(ans)
|
p03102
|
n,m,c = list(map(int,input().split()))
b = [int(_) for _ in input().split()]
a = []
ans = 0
for _ in range(n):
a.append([int(_) for _ in input().split()])
for i in range(n):
sum = 0
for j in range(m):
sum += a[i][j] * b[j]
if sum + c > 0:
ans += 1
else:
pass
print(ans)
|
n,m,c = list(map(int,input().split()))
b = [int(_) for _ in input().split()]
ans = 0
for _ in range(n):
a = [int(_) for _ in input().split()]
sum = 0
for j in range(m):
sum += a[j] * b[j]
if sum + c > 0:
ans += 1
print(ans)
|
p03102
|
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
a = list(map(int, input().split()))
val = 0
for j in range(m):
val += a[j] * b[j]
val += c
if val > 0:
cnt += 1
print (cnt)
|
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
a = list(map(int, input().split()))
cnt = 0
for j in range(m):
cnt += a[j]*b[j]
cnt += c
if cnt > 0:
res += 1
print (res)
|
p03102
|
N, M, C = list(map(int, input().split()))
Bi = list(map(int, input().split()))
count = 0
for i in range(N):
Ai = list(map(int, input().split()))
t = C
for i in range(M):
t += Ai[i] * Bi[i]
if t > 0:
count += 1
print(count)
|
N, M, C = list(map(int, input().split()))
Bi = list(map(int, input().split()))
Ai = [list(map(int, input().split())) for _ in range(N)]
count = 0
for a in Ai:
s = C
for i in range(M):
s += a[i] * Bi[i]
if s > 0:
count += 1
print(count)
|
p03102
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
cnt = 0
for i in range(N):
A.append(list(map(int, input().split())))
for a in range (N):
tl = 0
for b in range (M):
tl += A[a][b]*B[b]
if tl+C > 0:
cnt += 1
print(cnt)
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
cnt = 0
for i in range (N):
A.append(list(map(int,input().split())))
for j in range (N):
tl = 0
for k in range (M):
tl += A[j][k]*B[k]
if tl + C > 0:
cnt += 1
print(cnt)
|
p03102
|
n,m,c = list(map(int,input().split()))
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
a = [int(i) for i in input().split()]
sum = c
for i in range(m):sum+=b[i] * a[i]
ans+=sum > 0
print(ans)
|
n,m,c=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
a=list(map(int,input().split()))
sum=c
for j in range(m):sum+=a[j]*b[j]
if sum>0:ans+=1
print(ans)
|
p03102
|
n,m,c = list(map(int,input().split()))
b = list(map(int,input().split()))
a = [(list(map(int,input().split()))) for i in range(n)]
t = 0
for i in range(n):
z = 0
for j in range(m):
z += a[i][j] * b[j]
z += c
if z > 0:
t += 1
print(t)
|
n,m,c = list(map(int,input().split()))
b = list(map(int,input().split()))
a = [(list(map(int,input().split()))) for i in range(n)]
ans = 0
for i in range(n):
z = c
for j in range(m):
z += a[i][j] * b[j]
if z > 0:
ans += 1
print(ans)
|
p03102
|
import sys
input = sys.stdin.readline
def main():
ans = 0
n,m,c = list(map(int, input().split()))
b = list(map(int, input().split()))
for _ in range(n):
temp = 0
a = list(map(int, input().split()))
for j in range(m):
temp += a[j]*b[j]
if temp + c > 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
def main():
ans = 0
n,m,c = list(map(int, input().split()))
b = list(map(int, input().split()))
for _ in range(n):
temp = c
a = list(map(int, input().split()))
for j in range(m):
temp += a[j]*b[j]
if temp > 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
p03102
|
N,M,C=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(N)]
cnt=0
for i in range(N):
ans=0
for j in range(M):
ans += B[j]*A[i][j]
if ans+C>0:
cnt+=1
print(cnt)
|
N,M,C=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
for i in range(N):
am=0
A=list(map(int,input().split()))
for j in range(M):
am+=B[j]*A[j]
if am+C>0:
cnt+=1
print(cnt)
|
p03102
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
ct = 0
for i in A:
if sum([j * k for j, k in zip(i, B)]) + C > 0:
ct += 1
print(ct)
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
ct = 0
for i in range(N):
if sum([j * k for j, k in zip(list(map(int, input().split())), B)]) + C > 0:
ct += 1
print(ct)
|
p03102
|
import copy
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
As = []
for i in range(N):
As.append(list(map(int, input().split())))
correct_answer_num = 0
for A in As:
result = 0
for j in range(M):
result += A[j] * B[j]
result += C
if result > 0:
correct_answer_num += 1
print(("{}".format(correct_answer_num)))
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
As = []
for i in range(N):
As.append(list(map(int, input().split())))
correct_answer_num = 0
for A in As:
result = 0
for j in range(M):
result += A[j] * B[j]
result += C
if result > 0:
correct_answer_num += 1
print(("{}".format(correct_answer_num)))
|
p03102
|
N, M, C = list(map(int, input().split()))
blist = list(map(int, input().split()))
alist = [list(map(int, input().split())) for _ in range(N)]
res = 0
for i in range(N):
sum = 0
for j in range(M):
sum += alist[i][j] * blist[j]
if sum + C > 0:
res += 1
print(res)
|
N, M, C = list(map(int, input().split()))
blist = list(map(int, input().split()))
alist = [list(map(int, input().split())) for _ in range(N)]
print((sum([1 if sum(t[0]*t[1] for t in zip(alist[i], blist)) + C > 0 else 0 for i in range(N)])))
|
p03102
|
n,m,c=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[list(map(int,input().split()))for i in range(n)]
cnt=0
for i in range(n):
total=0
for j in range(m):
total+=B[j]*A[i][j]
total+=c
if 0<total:
cnt+=1
print(cnt)
|
N,M,C=list(map(int,input().split()))
B=list(map(int,input().split()))
A =[list(map(int,input().split()))for i in range(N)]
ans=0
for i in range(N):
X=0
for j in range(M):
X += A[i][j]*B[j]
X += C
if 0 < X:
ans += 1
print(ans)
|
p03102
|
N,M,C=list(map(int,input().split()))
B=list(map(int,input().split()))
A =[list(map(int,input().split()))for i in range(N)]
ans=0
for i in range(N):
X=0
for j in range(M):
X+=(A[i][j]*B[j])
X=X+C
if 0 < X:
ans = ans+1
print(ans)
|
n, m, c = list(map(int, input().split()))
blst = list(map(int, input().split()))
cnt = 0
for i in range(n):
judge = 0
alst = list(map(int, input().split()))
for j, k in zip(alst, blst):
judge += j * k
if judge + c > 0:
cnt += 1
print(cnt)
|
p03102
|
N, M, C = list(map(int, input().split()))
*B, = list(map(int, input().split()))
A = [tuple(map(int, input().split())) for _ in range(N)]
count = 0
for a in A:
j = 0
for ta, b in zip(a, B):
j += ta * b
if 0 < j + C:
count += 1
print(count)
|
N, M, C = list(map(int, input().split()))
*B, = list(map(int, input().split()))
count = 0
for _ in range(N):
count += (0 < sum(x * y for x, y in zip(tuple(map(int, input().split())), B)) + C)
print(count)
|
p03102
|
lx = list(map(int,input().split(" ")))
lb = list(map(int,input().split(" ")))
#la = [li[0]][li[1]]
la = []
cnt = 0
for i in range(0, lx[0]):
tmp = lx[2]
la.append(list(map(int,input().split(" "))))
for j in range(0, lx[1]):
tmp += la[i][j] * lb[j]
if (tmp > 0):
cnt += 1
print(cnt)
|
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))
#la = [li[0]][li[1]]
cnt = 0
for i in range(n):
a = list(map(int, input().split()))
tmp = c
for j in range(0, m):
tmp += a[j] * b[j]
if (tmp > 0):
cnt += 1
print(cnt)
|
p03102
|
N, M, C = list(map(int, input().split()))
Blis = [int(x) for x in input().split()]
k = 0
for i in range(N):
Alis = [int(x) for x in input().split()]
total = 0
for j in range(M):
total = total + (Alis[j])*(Blis[j])
total = total + C
if total > 0:
k = k + 1
print(k)
|
N, M, C = list(map(int, input().split()))
Blis = [int(x) for x in input().split()]
Alis = [x for x in range(N)]
k = 0
for i in range(N):
Alis[i] = [int(x) for x in input().split()]
for i in range(N):
total = 0
for j in range(M):
total = total + (Alis[i][j])*(Blis[j])
total = total + C
if total > 0:
k = k + 1
print(k)
|
p03102
|
N,M,C = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Alist = [list(map(int,input().split())) for i in range(N)]
counter = 0
for x in range(N):
all = C
xlist = Alist[x]
for j in range(M):
all += Blist[j]*xlist[j]
if all>0:
counter += 1
print(counter)
|
N, M, C = list(map(int, input().split()))
Blist = list(map(int, input().split()))
ans = 0
for i in range(N):
score = C
Alist = list(map(int, input().split()))
for j in range(M):
score += Alist[j]*Blist[j]
if score > 0:
ans += 1
print(ans)
|
p03102
|
n, m, c = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(n):
A = list(map(int, input().split()))
s = c
for a, b in zip(A, B): s += a*b
if s > 0: ans += 1
print(ans)
|
n, m, c = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(n):
A = list(map(int, input().split()))
s = c + sum([a*b for a, b in zip(A, B)])
if s > 0: ans += 1
print(ans)
|
p03102
|
n,m,c=list(map(int,input().split()))
b=list(map(int,input().split()))
a=[[0] * m for _ in range(n)]
for i in range(n):
a[i]=list(map(int,input().split()))
count=0
for i in range(n):
# print(sum(list(map(lambda a,b:a*b,a[i],b))))
if sum(list(map(lambda a,b:a*b,a[i],b)))+c > 0:
count+=1
print(count)
|
N,M,C=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i in range(N):
A=list(map(int,input().split()))
if sum(a*b for a,b in zip(A,B))+C>0:count+=1
print(count)
|
p03102
|
N,M,C = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for _ in range(N):
A = list(map(int, input().split()))
sums = sum([A[i]*B[i] for i in range(M)])+C
if sums > 0:
cnt += 1
print(cnt)
|
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in a:
if sum([j * k for j, k in zip(i, b)]) + c > 0:
cnt += 1
print(cnt)
|
p03102
|
N,M,C = list(map(int,input().split()))
B_ = list(map(int,input().split()))
A_ = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
sum_n = 0
for j in range(M):
sum_n += A_[i][j]*B_[j]
if sum_n+C > 0:
ans += 1
print(ans)
|
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
count = 0
for n in range(N):
cost = 0
for m in range(M):
cost += A[n][m]*B[m]
if cost + C > 0:
count += 1
print(count)
|
p03102
|
N, M, C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for a in A:
tmp = C
for i in range(M):
tmp += a[i]*B[i]
if(tmp > 0):
cnt += 1
print(cnt)
|
N, M, C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for a in A:
tmp = C
for j in range(M):
tmp += a[j]*B[j]
if tmp > 0:
ans += 1
print(ans)
|
p03102
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0]*N
count = 0
def a_x_b(ab):
a, b = ab
return a*b
for n in range(N):
A[n] = list(map(int, input().split()))
AB = [(A[n][i], B[i]) for i in range(M)]
if sum(list(map(a_x_b, AB)))+C > 0:
count += 1
else:
continue
print(count)
|
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0]*N
count = 0
for n in range(N):
A[n] = list(map(int, input().split()))
_sum = 0
for i in range(M):
_sum += A[n][i] * B[i]
if _sum + C > 0:
count += 1
else:
continue
print(count)
|
p03102
|
N,M,C=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i in range(N):
A=list(map(int,input().split()))
p=C
for j in range(M):p+=A[j]*B[j]
if p>0:count+=1
print(count)
|
n,m,c = list(map(int,input().split()))
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(n)]
count=0
t=c
for i in range(n):
for j in range(m):
t += a[i][j]*b[j]
if t > 0:
count += 1
t=c
print(count)
|
p03102
|
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
res = C
for j in range(M):
res += A[i][j]*B[j]
if res > 0:
ans += 1
print(ans)
|
N, M, C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
res = C
for j in range(M):
res += B[j] * A[i][j]
if res > 0:
ans += 1
print(ans)
|
p03102
|
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(eval(input()))
s=input().strip()
memo={}
def getans(a,b,c):
while a and c and a[0]==c[-1]:
a=a[1:]
c=c[:-1]
if b=="":
if a=="" and c=="": return 1
else: return 0
key=a+"/"+b+"/"+c
if key in memo: return memo[key]
# select first letter
ans=0
for i in range(1,len(b)):
if b[0]==b[i]:
ans+=getans(a,b[1:i],b[i+1:]+c)
# don't select first letter
ans+=getans(a+b[0],b[1:],c)
memo[key]=ans
#print(key,ans)
return ans
print((getans("",s,"")*2))
#print(len(memo))
|
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(eval(input()))
s=input().strip()
memo={}
def getans(a,b,c):
while a and c and a[0]==c[-1]:
a=a[1:]
c=c[:-1]
if a and c: return 0
if b=="":
if a=="" and c=="": return 1
else: return 0
key=a+"/"+b+"/"+c
if key in memo: return memo[key]
# select first letter
ans=0
for i in range(1,len(b)):
if b[0]==b[i]:
ans+=getans(a,b[1:i],b[i+1:]+c)
# don't select first letter
ans+=getans(a+b[0],b[1:],c)
memo[key]=ans
#print(key,ans)
return ans
print((getans("",s,"")*2))
#print(len(memo))
|
p03298
|
import sys
input = sys.stdin.readline
from collections import defaultdict
def main():
n = int(eval(input()))
s = input().strip()
pc = defaultdict(lambda: 0)
for i in range(pow(2, n)):
rd = ""
bl = ""
for b in range(n):
if (i // pow(2, b))%2 == 1:
rd += s[b]
else:
bl += s[b]
pc[(rd, bl)] += 1
ans = 0
s = s[::-1]
for i in range(pow(2, n)):
rd = ""
bl = ""
for b in range(n):
if (i // pow(2, b)) % 2 == 1:
bl += s[b]
else:
rd += s[b]
ans += pc[(rd, bl)]
print(ans)
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))
from collections import defaultdict
def main():
n = int(eval(input()))
s = input().strip()
tmp = defaultdict(lambda : 0)
for state in range(1 << n):
rs, bs = "", ""
for i in range(n):
if (state >> i) & 1:
rs += s[i]
else:
bs += s[i]
tmp[(rs, bs)] += 1
ans = 0
for state in range(1 << n):
rs, bs = "", ""
for i in range(n):
if (state >> i) & 1:
rs += s[-i - 1]
else:
bs += s[-i - 1]
ans += tmp[(rs, bs)]
print(ans)
if __name__ == '__main__':
main()
|
p03298
|
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
S = LS2()
# 左N個のマスをどう塗るかで半分全列挙
ans = 0
left = []
right = []
for i in range(2**N):
red = []
blue = []
for j in range(N):
if (i >> j) & 1:
red.append(S[j])
else:
blue.append(S[j])
red = ''.join(red)
blue = ''.join(blue)
left.append((red,blue))
for i in range(2**N):
red = []
blue = []
for j in range(N):
if (i >> j) & 1:
red.append(S[j+N])
else:
blue.append(S[j+N])
red,blue = blue,red
red.reverse()
blue.reverse()
red = ''.join(red)
blue = ''.join(blue)
right.append((red,blue))
from operator import itemgetter
right = sorted(right,key = itemgetter(0,1))
from bisect import bisect_left,bisect
ans = 0
for i in range(2**N):
ans += bisect(right,left[i]) - bisect_left(right,left[i])
print(ans)
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
S = LS2()
from collections import defaultdict
d_left = defaultdict(int)
d_right = defaultdict(int)
for i in range(2**N):
left_red = ''
left_blue = ''
right_red = ''
right_blue = ''
for j in range(N):
if (i >> j) & 1:
left_red += S[j]
else:
left_blue += S[j]
for j in range(2*N-1,N-1,-1):
if (i >> (j-N)) & 1:
right_red += S[j]
else:
right_blue += S[j]
d_left[(left_red,left_blue)] += 1
d_right[(right_red,right_blue)] += 1
ans = 0
for key in list(d_left.keys()):
ans += d_left[key]*d_right[key]
print(ans)
|
p03298
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
d = defaultdict(lambda : 0)
m = 1<<n
for i in range(m):
r = []
b = []
for j in range(n):
if i&(1<<j):
r.append(s[j])
else:
b.append(s[j])
r,b = b[::-1],r[::-1]
d[(tuple(r),tuple(b))] += 1
ans = 0
for i in range(m):
r = []
b = []
for j in range(n):
if i&(1<<j):
r.append(s[j+n])
else:
b.append(s[j+n])
ans += d[(tuple(r),tuple(b))]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
d = defaultdict(lambda : 0)
m = 1<<n
p = [1<<j for j in range(n)]
for i in range(m):
r = []
b = []
for j in range(n):
if i&p[j]:
r.append(s[j])
else:
b.append(s[j])
r,b = b[::-1],r[::-1]
d[(tuple(r),tuple(b))] += 1
ans = 0
for i in range(m):
r = []
b = []
for j in range(n):
if i&p[j]:
r.append(s[j+n])
else:
b.append(s[j+n])
ans += d[(tuple(r),tuple(b))]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
p03298
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
d = defaultdict(lambda : 0)
m = 1<<n
p = [1<<j for j in range(n)]
for i in range(m):
r = []
b = []
for j in range(n):
if i&p[j]:
r.append(s[j])
else:
b.append(s[j])
r,b = b[::-1],r[::-1]
d[(tuple(r),tuple(b))] += 1
ans = 0
for i in range(m):
r = []
b = []
for j in range(n):
if i&p[j]:
r.append(s[j+n])
else:
b.append(s[j+n])
ans += d[(tuple(r),tuple(b))]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
d = defaultdict(lambda : 0)
alp = list("abcdefghijklmnopqrstuvwxyz")
f = {}
for i in range(26):
f[alp[i]] = i+1
for i in range(2*n):
s[i] = f[s[i]]
for i in range(n>>1):
s[i],s[n-i-1] = s[n-i-1],s[i]
k = 27
m = 1<<n
p = [1<<j for j in range(n)]
for i in range(m):
r = 0
b = 0
for j in range(n):
if i&p[j]:
r *= k
r += s[j]
else:
b *= k
b += s[j]
d[(r,b)] += 1
ans = 0
for i in range(m):
r = 0
b = 0
for j in range(n):
if i&p[j]:
r *= k
r += s[j+n]
else:
b *= k
b += s[j+n]
ans += d[(r,b)]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
p03298
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
for i in range(n>>1):
s[i],s[n-i-1] = s[n-i-1],s[i]
d = defaultdict(lambda : 0)
m = 1<<n
for i in range(m):
r = []
b = []
for j in range(n):
if i&(1<<j):
r.append(s[j])
else:
b.append(s[j])
d[(tuple(r),tuple(b))] += 1
ans = 0
for i in range(m):
r = []
b = []
for j in range(n):
if i&(1<<j):
r.append(s[j+n])
else:
b.append(s[j+n])
ans += d[(tuple(r),tuple(b))]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
d = defaultdict(lambda : 0)
alp = list("abcdefghijklmnopqrstuvwxyz")
f = {}
for i in range(26):
f[alp[i]] = i+1
for i in range(2*n):
s[i] = f[s[i]]
for i in range(n>>1):
s[i],s[n-i-1] = s[n-i-1],s[i]
k = 27
m = 1<<n
p = [1<<j for j in range(n)]
for i in range(m):
r = 0
b = 0
for j in range(n):
if i&p[j]:
r *= k
r += s[j]
else:
b *= k
b += s[j]
d[(r,b)] += 1
ans = 0
for i in range(m):
r = 0
b = 0
for j in range(n):
if i&p[j]:
r *= k
r += s[j+n]
else:
b *= k
b += s[j+n]
ans += d[(r,b)]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
p03298
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
for i in range(2*n):
s[i] = ord(s[i])-96
for i in range(n>>1):
s[i],s[n-i-1] = s[n-i-1],s[i]
k = 27
m = 1<<n
p = [1<<j for j in range(n)]
d = defaultdict(lambda : 0)
for i in range(m):
r = 0
b = 0
for j in range(n):
if i&p[j]:
r *= k
r += s[j]
else:
b *= k
b += s[j]
d[(r,b)] += 1
ans = 0
for i in range(m):
r = 0
b = 0
for j in range(n):
if i&p[j]:
r *= k
r += s[j+n]
else:
b *= k
b += s[j+n]
ans += d[(r,b)]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
return
#C
def C():
n = I()
s = S()
for i in range(2*n):
s[i] = ord(s[i])-96
k = 27
m = 1<<n
p = [1<<j for j in range(n)]
d = defaultdict(lambda : 0)
l = [(0,0)]
for i in s[:n][::-1]:
l = [(x[0]*k+i, x[1]) for x in l]+[(x[0], x[1]*k+i) for x in l]
for i in l:
d[i] += 1
ans = 0
l = [(0,0)]
for i in s[n:]:
l = [(x[0]*k+i, x[1]) for x in l]+[(x[0], x[1]*k+i) for x in l]
for i in l:
ans += d[i]
print(ans)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
|
p03298
|
n, m = list(map(int, input().split()))
ab = []
for _ in range(n):
a, b = list(map(int, input().split()))
ab.extend([a for _ in range(b)])
ab.sort()
print((sum(ab[:m])))
|
n,m,*t = list(map(int, open(0).read().split()))
ans = 0
for a, b in sorted(zip(t[::2], t[1::2])):
ans += min(b, m)*a
m -= b
if m <= 0:
print(ans)
break
|
p03103
|
def main():
n, m = list(map(int, input().split()))
answer = 0
cost = [list(map(int, input().split())) for _ in range(n)]
cost.sort(key=lambda x: x[0])
for c, num in cost:
if m < 0:
break
answer += c * min(m, num)
m -= min(m, num)
print(answer)
if __name__ == '__main__':
main()
|
def main():
n, m = list(map(int, input().split()))
info = []
for _ in range(n):
info.append(list(map(int, input().split())))
info.sort(key=lambda x: x[0])
answer = 0
for a, b in info:
if m <= 0:
break
answer += a * min(b, m)
m -= min(b, m)
print(answer)
if __name__ == '__main__':
main()
|
p03103
|
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
for _ in range(b):
if i < m:
ans+=a
i+=1
print(ans)
|
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
for _ in range(b):
if i < m:
ans+=a
i+=1
else:
break
print(ans)
|
p03103
|
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
#print(lis)
price=0
i=0
while m>0:
price+=lis[i][0]*min(m,lis[i][1])
m-=min(m,lis[i][1])
#print(price)
i+=1
print(price)
|
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
pay=0
i=0
while m>0:
pay+=lis[i][0]*min(m,lis[i][1])
m-=min(m,lis[i][1])
i+=1
print(pay)
|
p03103
|
from functools import reduce
N, M = list(map(int,input().split()))
ary1 =[]
for x in range(N):
ary1.append(list(map(int,input().split())))
ary2 = sorted(ary1)
print((sum(reduce(lambda a,b: a+b ,[[x[0]]*x[1] for x in ary2])[0:M])))
|
from functools import reduce
N, M = list(map(int,input().split()))
ary1 =[]
for x in range(N):
ary1.append(list(map(int,input().split())))
ary2 = sorted(ary1)
count = 0
total_sum = 0
for i in range(N):
if count + ary2[i][1] <= M:
total_sum += ary2[i][0] * ary2[i][1]
count += ary2[i][1]
elif count > M :
break
else:
zan = M - count
total_sum += ary2[i][0] * zan
count += zan
print(total_sum)
|
p03103
|
from sys import stdin
def a(input_string):
N, M = [int(x) for x in input_string[0].split()]
C = input_string[1:]
temp = [string.split() for string in C]
D = []
for i in range(len(temp)):
D.append([int(word) for word in temp[i]])
#print(D)
get_count = 0
min_cost = 10000000000000000
cost = 0
D = sorted(D, key=lambda x: x[0])
for i in range(N):
for j in range(D[i][1]):
get_count += 1
cost += D[i][0]
if get_count >= M:
if cost < min_cost:
min_cost = cost
return min_cost
def main():
input_line = stdin.readlines()
answer = a(input_line)
print(answer)
if __name__ == '__main__':
main()
|
from sys import stdin
def a(input_string):
N, M = [int(x) for x in input_string[0].split()]
C = input_string[1:]
temp = [string.split() for string in C]
D = []
for i in range(len(temp)):
D.append([int(word) for word in temp[i]])
#print(D)
get_count = 0
min_cost = 10000000000000000
cost = 0
D = sorted(D, key=lambda x: x[0])
for i in range(N):
for j in range(D[i][1]):
get_count += 1
cost += D[i][0]
if get_count >= M:
return cost
return cost
def main():
input_line = stdin.readlines()
answer = a(input_line)
print(answer)
if __name__ == '__main__':
main()
|
p03103
|
N,M=list(map(int,input().split()))
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
for i in range(ab[1]):
if M>0:
M-=1
cost+=ab[0]
print(cost)
|
N,M=list(map(int,input().split()))
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
if M>=ab[1]:
M-=ab[1]
cost+=ab[0]*ab[1]
else:
cost+=ab[0]*M
break
print(cost)
|
p03103
|
from collections import deque
N, M = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
C = deque()
while len(C) < M:
for j in range(B[A.index(min(A))]):
if len(C) < M:
C.append(min(A))
else:
break
B.pop(A.index(min(A)))
A.remove(min(A))
C = sorted(C)
print((sum(C[:M])))
|
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = deque()
for i in range(N):
A.append(list(map(int, input().split())))
A = sorted(A, key=itemgetter(0))
m=0
cost=0
for i in range(N):
if m >= M:
break
buy = min(M - m, A[i][1])
cost += A[i][0] * buy
m += buy
print(cost)
|
p03103
|
n, m = list(map(int, input().split()))
x = [[int(j) for j in input().split()] for i in range(n)]
a = []
b = []
for i in range(n):
a.append(x[i][0])
b.append(x[i][1])
mon = 0
cnt = 0
ind = 100000
while(cnt < m):
min = 10000000000
for i in range(n):
if a[i] < min:
min = a[i]
ind = i
while(b[ind] > 0 and cnt != m):
cnt += 1
mon += a[ind]
b[ind] -= 1
a[ind] = 100000000000
print(mon)
|
import math
n, m = list(map(int, input().split()))
a = []
for i in range(n):
l = list(map(int, input().split()))
a.append(l)
a.sort(key=lambda x: x[0])
sum = 0
cnt = 0
for i in range(n):
if cnt + a[i][1] >= m:
sum += (m-cnt)*a[i][0]
cnt += m-cnt
break
else:
sum += a[i][0]*a[i][1]
cnt += a[i][1]
print(sum)
|
p03103
|
n,m=list(map(int,input().split()))
xy=[]
for i in range(n):
a,b=list(map(int,input().split()))
xy.append((a,b))
xy=sorted(xy)
ans=0
for p,c in xy:
if m>=c:
ans+=p*c
m-=c
else:
ans+=p*m
m=0
break
print(ans)
|
n, m = list(map(int,input().split()))
drinks = []
for i in range(n):
a,b= list(map(int,input().split()))
drinks.append((a,b))
drinks.sort()
ans = 0
for x,y in drinks:
if y < m:
ans += x*y
m -= y
else:
ans += x*m
break
print(ans)
|
p03103
|
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
ans = 0
res = M
for v in X:
ans += v[0] * min(v[1], res)
res -= v[1]
if res <= 0:
break
print(ans)
|
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
res = M
ans = 0
for a, b in X:
if res <= 0:
break
tmp = min(b, res)
res -= tmp
ans += tmp * a
print(ans)
|
p03103
|
n, m = list(map(int, input().split()))
a, b = [0]*n, [0]*n
for i in range(n):
a[i], b[i] = list(map(int, input().split()))
flag = 1
while flag:
flag = 0
for j in range(n-1):
if a[j] > a[j+1]:
tmp = a[j]
a[j] = a[j+1]
a[j+1] = tmp
res = b[j]
b[j] = b[j+1]
b[j+1] = res
flag = 1
ans = 0
for i in range(n):
if m > b[i]:
ans += a[i]*b[i]
m -= b[i]
else:
ans += m*a[i]
break
print(ans)
|
n, m = list(map(int, input().split()))
a = [0]*n
for i in range(n):
a[i] = list(map(int, input().split()))
a.sort(key=lambda x: x[0])
ans = 0
for i in range(n):
if m > a[i][1]:
ans += a[i][0]*a[i][1]
m -= a[i][1]
else:
ans += m*a[i][0]
break
print(ans)
|
p03103
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.