input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys from pprint import pprint bingo = [[] for _ in range(3)] for i in range(3): bingo[i] = list(map(int, sys.stdin.readline().strip().split())) N = int(sys.stdin.readline().strip()) B = set() for _ in range(N): B.add(int(sys.stdin.readline().strip())) bingo_flag = False for i in range(3):...
import sys input = sys.stdin.readline bingo = [] for _ in range(3): bingo.append(list(map(int, input().split()))) N = int(eval(input())) nums = [] for _ in range(N): nums.append(int(eval(input()))) for num in nums: for i in range(3): for j in range(3): if bingo[i][j] ...
p02760
def main(): top = list(map(int, input().split())) middle = list(map(int, input().split())) bottom = list(map(int, input().split())) N = int(eval(input())) taken = [] for f in range(N): taken.append(int(eval(input()))) bingo = [] bingo.append(top) bingo.append(...
def main(): top = list(map(int, input().split())) middle = list(map(int, input().split())) bottom = list(map(int, input().split())) N = int(eval(input())) taken = [] for i in range(N): taken.append(int(eval(input()))) bingo = [] bingo.append(top) bingo.append(...
p02760
A = [] for i in range(3): A.append(list(map(int, input().split()))) N = int(eval(input())) b = [] for i in range(N): b.append(int(eval(input()))) for i in range(3): if A[i][0] in b and A[i][1] in b and A[i][2] in b: print('Yes') exit() for i in range(3): if A[0][i] in b...
a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) a3 = list(map(int, input().split())) n = int(eval(input())) a = [] ans = 0 for i in range(n): b = int(eval(input())) a.append(b) for i in range(3): if a1[i] in a and a2[i] in a and a3[i] in a: ans = 'Yes' if a1[0]...
p02760
A = sum([list(map(int, input().split())) for _ in range(3)], []) N = int(eval(input())) ans = 0 for _ in range(N): b = int(eval(input())) if b in A: A[A.index(b)] = 0 if ( A[0] + A[1] + A[2] == 0 or A[3] + A[4] + A[5] == 0 or A[6] + A[7] + A[8] == 0 or ...
A = sum([list(map(int, input().split())) for _ in range(3)], []) N = int(eval(input())) for _ in range(N): b = int(eval(input())) if b in A: A[A.index(b)] = 0 if ( A[0] + A[1] + A[2] == 0 or A[3] + A[4] + A[5] == 0 or A[6] + A[7] + A[8] == 0 or A[0] + A[3]...
p02760
A=[] for _ in range(3): A+=list(map(int,input().split())) N=int(eval(input())) for _ in range(N): b=int(eval(input())) if b in A: A[A.index(b)]=0 p=[ (0,1,2),(3,4,5),(6,7,8), (0,3,6),(1,4,7),(2,5,8), (0,4,8),(2,4,6), ] for i,j,k in p: if A[i]==A[j]==A[k]==0: pr...
A=[] for _ in range(3): A+=list(map(int,input().split())) N=int(eval(input())) for _ in range(N): b=int(eval(input())) if b in A: A[A.index(b)]=0 p=[ (0,1,2),(3,4,5),(6,7,8), (0,3,6),(1,4,7),(2,5,8), (0,4,8),(2,4,6), ] for i,j,k in p: if A[i]==A[j]==A[k]: print...
p02760
def f(): a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) a3 = list(map(int, input().split())) A = a1+a2+a3 N = int(eval(input())) c = [False]*9 for i in range(N): b = int(eval(input())) if b in A: c[A.index(b)] = True for i in range(3): if ...
*A, = list(map(int, open(0).read().split())) N = A[9] B = A[10:] A = A[:9] T = [False]*9 for b in B: if b in A: T[A.index(b)] = True bingo = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)] for a, b, c in bingo: if T[a] and T[b] and T[c...
p02760
a = [list(map(int, input().split())) for _ in range(3)] n = int(eval(input())) b = [int(eval(input())) for _ in range(n)] mark = [[False, False, False] for _ in range(3)] for i in range(3): for j in range(3): if a[i][j] in b:mark[i][j] = True ans = 'No' for i in range(3): if mark[i][0] and ma...
a = [list(map(int, input().split())) for _ in range(3)] n = int(eval(input())) b = [int(eval(input())) for _ in range(n)] mark = [[False, False, False] for _ in range(3)] for i in range(3): for j in range(3): if a[i][j] in b:mark[i][j] = True ans = 'No' for i in range(3): if all(mark[i]): ...
p02760
A = [list(map(int, input().split())) for _ in range(3)] N = int(eval(input())) b = [int(eval(input())) for _ in range(N)] field = 0 for v in b: for i in range(9): if A[i // 3][i % 3] == v: field = field | (1 << i) ans = False for v in sum([[273,84],sum([[73<<i,7<<i*3]for i in range(3)],[])],[]): ans...
A = [list(map(int, input().split())) for _ in range(3)] N = int(eval(input())) b = [int(eval(input())) for _ in range(N)] f=0 for v in b: for i in range(9): if A[i // 3][i % 3] == v: f|=1<<i ans = 0 for v in [7,56,73,84,146,273,292,448]: ans |= f&v==v; print(('Yes' if ans else 'No'))
p02760
p,r=input,range A=sum([list(map(int,p().split()))for _ in r(3)],[]) b=[int(p())for _ in r(int(p()))] print(('Yes'if[v for v in[7,56,73,84,146,273,292,448]if sum(1<<i for i in r(9)if A[i]in b)&v==v]else'No'))
p,r=input,range A=sum([list(map(int,p().split()))for _ in r(3)],[]) b=[int(p())for _ in r(int(p()))] print(('YNeos'[all([sum(1<<i for i in r(9)if A[i]in b)&v!=v for v in[7,56,73,84,146,273,292,448]])::2]))
p02760
A = [list(map(int,input().split())) for i in range(3)] N = int(eval(input())) b = [int(eval(input())) for i in range(N)] cnt = [0]*8 ans = "No" for i in range(3): for j in range(3): if A[i][j] in b: cnt[i] += 1 cnt[j+3] += 1 if i== j: cnt[-2] +=...
A = [list(map(int,input().split())) for i in range(3)] N = int(eval(input())) b = [int(eval(input())) for i in range(N)] cnt = [0]*8 ans = "No" for i in range(3): for j in range(3): if A[i][j] in b: cnt[i] += 1 cnt[j+3] += 1 if i == j: cnt[-1] +...
p02760
from collections import defaultdict def a(): A = [] A += list(map(int,input().split())) A += list(map(int,input().split())) A += list(map(int,input().split())) N = int(eval(input())) d = defaultdict(int) for _ in range(N): d[int(eval(input()))] = 1 B = list([d[x] for ...
(lambda A:(lambda N:(lambda C:(lambda d:(lambda B:print (["No","Yes"][3 in{sum(B[2: 8:2]),sum(B[::4])}|{sum(B[i *3:i*3+3])for i in range(3) } | { sum(B[i::3] )for i in range(3)} ] ) ) ( list(map( lambda x:d[x],A))))([x in C for x in range(101)]))({int (input())for x in range(N)} ))(int(input())))(list(map( i...
p02760
array_1 = [] for i in range(3): line = input().rstrip().split(' ') array_1.append(line) # print(array_1) bool_array = [] for i in range(3): tmp = [] for j in range(3): tmp.append(False) bool_array.append(tmp) # print(bool_array) num = int(input().rstrip()) for i in r...
array_1 = [] for i in range(3): line = input().rstrip().split(' ') array_1.append(line) bool_array = [] for i in range(3): tmp = [] for j in range(3): tmp.append(False) bool_array.append(tmp) num = int(input().rstrip()) for i in range(num): input_line = input().rstrip() ...
p02760
def myAnswer(A:list,B:list,N:int) -> str: bingo=[[0,0,0] for i in range(3)] for b in B: for i,a in enumerate(A): if(b in a): bingo[i][a.index(b)] = 1 break tate=[0,0,0] for n,b in enumerate(bingo): if(sum(b) == 3): return "Yes" for i i...
def myAnswer(A: list, B: list, N: int) -> str: bingoCard = [[0, 0, 0] for i in range(3)] row = [0, 0, 0] # マスが空くがどうかの判定 for b in B: for i, a in enumerate(A): if(b in a): bingoCard[i][a.index(b)] = 1 row[a.index(b)] += 1 break ...
p02760
x = list(map(int,input().split())) y = list(map(int,input().split())) z = list(map(int,input().split())) n = int(eval(input())) b = list(int(eval(input())) for i in range(n)) for i in range(n): if b[i] in x: x[x.index(b[i])] = 'T' if b[i] in y: y[y.index(b[i])] = 'T' if b[i] in z...
x = list(map(int,input().split())) y = list(map(int,input().split())) z = list(map(int,input().split())) n = int(eval(input())) for i in range(n): b = int(eval(input())) if b in x: x[x.index(b)] = 'T' if b in y: y[y.index(b)] = 'T' if b in z: z[z.index(b)] = 'T' if x[...
p02760
#Biginner Contest 157 B-Bingo #二次元配列を使う(3*3) bingonum=[[0,0,0],[0,0,0],[0,0,0]] bingo=[["False","False","False"],["False","False","False"],["False","False","False"]] for i in range(3): bingonum[i][0],bingonum[i][1],bingonum[i][2] = list(map(int,input().split())) N = int(eval(input())) b=[] for _ in range(...
bingonum=[[0,0,0],[0,0,0],[0,0,0]] bingo=[["False","False","False"],["False","False","False"],["False","False","False"]] for i in range(3): bingonum[i][0],bingonum[i][1],bingonum[i][2] = list(map(int,input().split())) N = int(eval(input())) b=[] for _ in range(N): b.append(int(eval(input()))) for x in...
p02760
from collections import defaultdict def main(): def is_in(a, b): return (a, b) in nums_points flag = 0 row1 = list(map(int, input().split())) row2 = list(map(int, input().split())) row3 = list(map(int, input().split())) n = int(eval(input())) nums = [int(eval(input...
from collections import defaultdict def main(): def is_in(a, b): return (a, b) in nums_points flag = 0 mat = [ list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())) ] n = int(eval(input())) nums = [i...
p02760
A = [list(map(int, input().split())) for i in range(3)] N = int(eval(input())) m = [[0]*3 for i in range(3)] ans,l,r = 0,0,0 for _ in range(N): b = int(eval(input())) for i in range(3): if b in A[i]: m[i][A[i].index(b)]=1 for i in range(3): t = sum(m[i]) l += m[i][i] y ...
A = [list(map(int, input().split())) for i in range(3)] N = int(eval(input())) m = [[0]*3 for i in range(3)] ans,l,r = 0,1,1 for _ in range(N): b = int(eval(input())) for i in range(3): if b in A[i]: m[i][A[i].index(b)]=1 for i in range(3): l *= m[i][i] t,y = 1,1 for j ...
p02760
bingo = [list(map(int, input().split())) for i in range(3)] n = int(eval(input())) nums = [int(eval(input())) for i in range(n)] res = 'No' for num in nums: for i in range(3): if num in bingo[i]: j = bingo[i].index(num) bingo[i][j] = 0 if sum(bingo[i]) == 0 or su...
bingo = [list(map(int, input().split())) for i in range(3)] n = int(eval(input())) for i in range(n): num = int(eval(input())) for j in range(3): for k in range(3): if bingo[j][k] == num: bingo[j][k] = 0 break; res = 'No' for i in range(3): if b...
p02760
b1 = [int(x) for x in input().split()] b2 = [int(x) for x in input().split()] b3 = [int(x) for x in input().split()] n = int(eval(input())) li = list() for i in range(n): li.append(int(eval(input()))) b1_0 = False b1_1 = False b1_2 = False b2_0 = False b2_1 = False b2_2 = False b3_0 = False b3_1 = F...
a = list() for i in range(3): a.append([int(x) for x in input().split()]) n = int(eval(input())) b = list() for i in range(n): b.append(int(eval(input()))) appear = [[0,0,0],[0,0,0],[0,0,0]] for i in range(3): for j in range(3): for k in b: if (a[i][j] == k): ...
p02760
import sys Field = [] for i in range(3): a, b, c = list(map(int, input().split(" "))) local = [a,b,c] Field.append(local) N = int(eval(input())) for i in range(N): target = int(eval(input())) for i in Field: if target in i: k = i.index(target) i[k] = -1 ...
Field = [list(map(int, input().split(" "))) for i in range(3)] N = int(eval(input())) num =[] for i in range(N): t = int(eval(input())) num.append(t) count=0 for i in Field: for t in range(3): if i[t] in num: i[t] = 0 for i in Field: if sum(i) == 0: count+=1 ...
p02760
A = [list(map(int,input().split())) for _ in range(3)] N = int(eval(input())) B = [int(eval(input())) for _ in range(N)] for i in range(3): bng = 1 for j in range(3): if A[i][j] in B: continue else: bng = 0 break if bng ==1:break if bng==1: ...
A = [list(map(int,input().split())) for _ in range(3)] N = int(eval(input())) B = [[0 for _ in range(3)] for _ in range(3)] for _ in range(N): b = int(eval(input())) for i in range(3): for j in range(3): if A[i][j]==b: B[i][j] = 1 flag = 0 for i in range(3): if...
p02760
*a,=list(map(int,open(0).read().split()));print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
p02760
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
p02760
A1=list(map(int, input().split())) A2=list(map(int, input().split())) A3=list(map(int, input().split())) A=A1+A2+A3 N=int(eval(input())) s=set() for _ in range(N): b=int(eval(input())) if b in A: s|={A.index(b)} bingo=[{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}] print((["No","Yes...
A1=list(map(int, input().split())) A2=list(map(int, input().split())) A3=list(map(int, input().split())) A=A1+A2+A3 N=int(eval(input())) s=set() for _ in range(N): b=int(eval(input())) if b in A: s|={A.index(b)} bingo=[{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,5,8},{2,4,6},{3,4,5},{6,7,8}] print((['No','Yes...
p02760
a = [] for i in range(3): a1, a2, a3 = list(map(int, input().split())) a.append(a1) a.append(a2) a.append(a3) l = [0]*9 n = int(eval(input())) for i in range(n): b = int(eval(input())) if b in a: l[a.index(b)] += 1 if l[0] == 1 and l[1] == 1 and l[2] == 1: print('Y...
a = [] for i in range(3): a1, a2, a3 = list(map(int, input().split())) a.append(a1) a.append(a2) a.append(a3) l = [0]*9 n = int(eval(input())) for i in range(n): b = int(eval(input())) for k in range(9): if a[k] == b: l[k] += 1 if l[0] == 1 and l[1] == 1 a...
p02760
A1 = list(map(int,input().split())) A2 = list(map(int,input().split())) A3 = list(map(int,input().split())) n = int(eval(input())) A = [[0,0,0],[0,0,0],[0,0,0]] for _ in range(n): b = int(eval(input())) if b in A1: tmp = A1.index(b) A[0][tmp] = 1 elif b in A2: tmp = A2...
A1 = list(map(int,input().split())) A2 = list(map(int,input().split())) A3 = list(map(int,input().split())) n = int(eval(input())) A = [[0,0,0],[0,0,0],[0,0,0]] for _ in range(n): b = int(eval(input())) if b in A1: tmp = A1.index(b) A[0][tmp] = 1 elif b in A2: tmp = A2...
p02760
import sys def input(): return sys.stdin.readline().strip() def main(): a = [[0]*3 for i in range(3)] for i in range(3): a[i] = list(map(int, input().split())) n = int(eval(input())) b = [0]*n bingo = "No" for i in range(n): b[i] = int(eval(input())) ...
import sys def input(): return sys.stdin.readline().strip() a = [[0]*3 for i in range(3)] for i in range(3): a[i] = list(map(int, input().split())) n = int(eval(input())) b = [0]*n bingo = "No" for i in range(n): b[i] = int(eval(input())) for k in range(3): if a[k][0] == ...
p02760
A = [[]]*3 for T in range(0,3): A[T] = [int(x) for x in input().split()] A = sum(A,[]) ATF = [False]*9 N = int(eval(input())) for TT in range(0,N): B = int(eval(input())) if B in A: ATF[A.index(B)] = True Flag = 0 if (all(ATF[:3])) or (all(ATF[3:6])) or (all(ATF[6:])): Flag =...
A = [[]]*3 for T in range(0,3): A[T] = [int(x) for x in input().split()] A = sum(A,[]) ATF = [False]*9 N = int(eval(input())) for TT in range(0,N): B = int(eval(input())) if B in A: ATF[A.index(B)] = True Flag = False if (all(ATF[:3])) or (all(ATF[3:6])) or (all(ATF[6:])): F...
p02760
def resolve(): A1 = list(map(int, input().split())) A2 = list(map(int, input().split())) A3 = list(map(int, input().split())) N = int(eval(input())) b = [int(eval(input())) for i in range(N)] A = A1 + A2 + A3 checkA = [0]*9 for i in range(N): if b[i] in A: ...
def resolve(): A1 = list(map(int, input().split())) A2 = list(map(int, input().split())) A3 = list(map(int, input().split())) N = int(eval(input())) b = [int(eval(input())) for i in range(N)] A = A1 + A2 + A3 checkA = [0]*9 for i in range(N): if b[i] in A: ...
p02760
def B(): a = [list(map(int,input().split())) for i in range(3)] n = int(eval(input())) #b = [list(map(int,input().split())) for i in range(n)] for bingo in (int(eval(input())) for _ in range(n)): for i in range(3): for j in range(3): if a[i][j] == bingo: ...
def B(): a = [list(map(int,input().split())) for i in range(3)] n = int(eval(input())) #b = [list(map(int,input().split())) for i in range(n)] for bingo in (int(eval(input())) for _ in range(n)): for i in range(3): for j in range(3): if a[i][j] == bingo: ...
p02760
#!/usr/bin/env python3 import sys # input a = [['' for _ in range(3)] for _ in range(3)] a[0] = list(map(int, input().split())) a[1] = list(map(int, input().split())) a[2] = list(map(int, input().split())) n = int(eval(input())) b = [] for _ in range(n): tmp = int(eval(input())) b.append(tmp) # ...
#!/usr/bin/env python3 import sys # input a = [list(map(int, input().split())) for _ in range(3)] n = int(eval(input())) b = [int(eval(input())) for _ in range(n)] # calc f = [[0 for _ in range(3)] for _ in range(3)] for i in range(3): for j in range(3): if a[i][j] in b: f[i][j] ...
p02760
N,M = list(map(int, input().split())) xyz = [tuple(map(int, input().split())) for _ in range(N)] constraint = [] for x,y,z in xyz: ci = [] for b in range(8): v = 0 if (b>>0)&1==1: v += x else: v -= x if (b>>1)&1==1: v += y else: v -= y if (b>>2)&1==1...
if __name__ == '__main__': N,M = list(map(int, input().split())) xyz = [tuple(map(int, input().split())) for _ in range(N)] constraint = [] for x,y,z in xyz: ci = [] for b in range(8): v = 0 if (b>>0)&1==1: v += x else: v -= x ...
p03326
import itertools N,M = [int(i) for i in input().split(' ')] x = [] for i in range(N): x.append([int(i) for i in input().split(' ')]) ans = 0 p = list(itertools.permutations(x,M)); for i in p: A=0 B =0 C=0 for j in range(M): A += i[j][0] B += i[j][1] C += i...
import itertools N,M = [int(i) for i in input().split(' ')] x = [] for i in range(N): x.append([int(i) for i in input().split(' ')]) tab = [0]*N ans = 0 #p = list(itertools.permutations(x,M)); for S in [[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]: for j in range(N):...
p03326
[N, M] = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(N)] def value(xyz, sign): return sum([xyz[i]*(1 - 2*((sign & (1 << i)) >> i)) for i in range(3)]) print((0 if M == 0 else max([sum([value(a[j], sign) for j in sorted([i for i in range(N)], key = lambda index : value(a[inde...
[N, M] = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(N)] def v(x, s): return sum([x[i]*(1 - 2*((s & (1 << i)) >> i)) for i in range(3)]) print((0 if M == 0 else max([sum([v(a[j], s) for j in sorted([i for i in range(N)], key = lambda i : v(a[i], s))[-M:]]) for s in range(8)]...
p03326
[N, M] = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(N)] def v(x, s): return sum([x[i]*(1 - 2*((s & (1 << i)) >> i)) for i in range(3)]) print((0 if M == 0 else max([sum([v(a[j], s) for j in sorted([i for i in range(N)], key = lambda i : v(a[i], s))[-M:]]) for s in range(8)]...
[N, M] = list(map(int, input().split())) a = eval('input().split(),'*N) print((0 if M==0 else max([sum(sorted([sum([int(x[b])*(s>>b&1or-1)for b in range(3)]) for x in a])[-M:])for s in range(8)])))
p03326
n,m = list(map(int, input().split())) a=[] for i in range(n): a.append(tuple(map(int, input().split()))) dp = [] for i in range(m+1): dp.append([0 for j in range(n+1)]) def f(fn): global dp, a for i in range(1,m+1): for j in range(1,n+1): dp[i][j] = max(dp[i][j-1], dp[...
n,m = list(map(int, input().split())) a=[] for i in range(n): a.append(tuple(map(int, input().split()))) dp = [] for i in range(m+1): dp.append([0 for j in range(n+1)]) def f(fn): global dp, a for i in range(1,m+1): for j in range(i,n+1): if j == i: dp...
p03326
N,M = list(map(int,input().split())) cake = [list(map(int,input().split())) for _ in range(N)] ans = 0 for i in range(8): sign = [0,0,0] for j in range(3): sign[j] = (i>>j & 1) cake_i = [] for k in range(N): s = 0 for j in range(3): s += cake[k][j]*(1-2*s...
N, M = list(map(int, input().split())) C = [tuple(map(int, input().split())) for _ in range(N)] res = 0 for i in range(8): D = [0 for _ in range(N)] for j in range(N): x, y, z = C[j] if (i >> 0) & 1: D[j] += x else: D[j] -= x if (i >> 1) & 1...
p03326
# ABC100D - Patisserie ABC def calc(func: "func") -> int: cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)] cakes.sort(reverse=1) return sum(cakes[:M]) def main(): global M, XYZ N, M, *XYZ = list(map(int, open(0).read().split())) ans = max( calc(lambda x, y, z: x ...
# ABC100D - Patisserie ABC def calc(func: "func") -> int: cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)] cakes.sort(reverse=1) return max(sum(cakes[:M]), -sum(cakes[-M:])) def main(): global M, XYZ N, M, *XYZ = list(map(int, open(0).read().split())) if M == 0: ...
p03326
n,m=list(map(int,input().split())) x,y,z=[],[],[] for i in range(n): xi,yi,zi=list(map(int,input().split())) x.append(xi) y.append(yi) z.append(zi) ans=0 for i in range(2**3): op=['-','-','-'] for j in range(3): if (i>>j)&1: op[j]='+' tx=x[::] ty=y[::] tz=z[::] if op[...
n,m=list(map(int,input().split())) xyz=[list(map(int,input().split())) for i in range(n)] ans=0 for i in [-1,1]: for j in [-1,1]: for k in [-1,1]: l=[i*xyz[z][0]+j*xyz[z][1]+k*xyz[z][2] for z in range(n)] l.sort(reverse=True) ans=max(ans,sum(l[:m])) print(ans)
p03326
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) n,m=nii() l=[lnii() for i in range(n)] ans=0 for i in range(2**3): t_l=[] for j in l: t_num=0 for k in range(3): if (i>>k)&1: t_num+=j[k] else: ...
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) n,m=nii() l=[lnii() for i in range(n)] ans=0 for i in [1,-1]: for j in [1,-1]: for k in [1,-1]: t_num=0 t_l=[] for x,y,z in l: t_num=x*i+y*j+z*k ...
p03326
import sys def input(): return sys.stdin.readline().strip() def main(): N, M = list(map(int, input().split())) cakes = [(0, 0, 0)] for _ in range(N): x, y, z = list(map(int, input().split())) cakes.append((x, y, z)) """ dp[n][m][t] = (1~n番目までのケーキからm個のケーキをタイプtで選んだ時の合計の最...
import sys def input(): return sys.stdin.readline().strip() def main(): N, M = list(map(int, input().split())) cakes = [(0, 0, 0)] for _ in range(N): x, y, z = list(map(int, input().split())) cakes.append((x, y, z)) """ これはdpするべきではなかった。O(NlogN)で解ける。 単純にx+y+zやx-y-z...
p03326
from itertools import combinations from sys import stdin, stdout input = lambda: stdin.readline().rstrip() println = stdout.write def main(): N, M = list(map(int, input().split())) XYZ = [tuple(map(int, input().split())) for _ in [0] * N] ans = -float('inf') for cake in combinations(XYZ, M):...
from itertools import combinations, product from sys import stdin, stdout input = lambda: stdin.readline().rstrip() println = stdout.write def main(): N, M = list(map(int, input().split())) XYZ = [tuple(map(int, input().split())) for _ in [0] * N] cake = [0] * N ans = -float('inf') for ...
p03326
# input N, M = list(map(int, input().split())) Cake = [list(map(int, input().split())) for i in range(N)] Cake_sum = {i:0 for i in range(N)} # x_i, y_i, z_iの合計の正負で8通りに場合分け # x_i >= 0, y_i >= 0, z_i >= 0 ans1 = 0 for i in range(N): Cake_sum[i] = Cake[i][0] + Cake[i][1] + Cake[i][2] Cake_sorted = so...
# input N, M = list(map(int, input().split())) Cake = [list(map(int, input().split())) for i in range(N)] Cake_sum = [0 for i in range(N)] # sum(x_i), sum(y_i), sum(z_i)の正負で8通りに場合分け # x_i >= 0, y_i >= 0, z_i >= 0 ans1 = 0 for i in range(N): Cake_sum[i] = Cake[i][0] + Cake[i][1] + Cake[i][2] Cake_sum...
p03326
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) xyz = [list(map(int, input().split())) for _ in range(N)] ans = 0 for bit in range(1 << 3): dp = [-float('inf')] * (M+1) dp[0] = 0 for i in range(N): for j in range(M)[::-1]: if dp[j] != -float('inf'...
N, M = list(map(int, input().split())) xyz = [list(map(int, input().split())) for _ in range(N)] ans = 0 for bit in range(1 << 3): scores = [0] * N for i in range(N): for j in range(3): scores[i] += xyz[i][j] * (-1)**((bit >> j) & 1) scores.sort(reverse=True) ans = max(ans, ...
p03326
N,M=list(map(int,input().split())) xyz=[] for i in range(N): xyz.append(list(map(int,input().split()))) coefs=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1] ,[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]] ans=[] for ix,iy,iz in coefs: xyz_ = [sum([ix*l[0],iy*l[1],iz*l[2]]) for l in xyz] dp=[[0]*(M+1) for ...
N,M=list(map(int,input().split())) xyz=[] for i in range(N): xyz.append(list(map(int,input().split()))) coefs=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1] ,[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]] ans=[] for ix,iy,iz in coefs: xyz_ = [sum([ix*l[0],iy*l[1],iz*l[2]]) for l in xyz] ans.append(sum(sor...
p03326
N, M = list(map(int, input().split())) cake = [list(map(int, input().split())) for _ in range(N)] dp = [[[0] * 8 for _ in range(M + 1)] for _ in range(N + 1)] for i in range(1, N + 1): x, y, z = cake[i - 1] for j in range(1, M + 1): for msk in range(8): mx = x * (1 - 2 * (msk >> 2...
N, M = list(map(int, input().split())) cake = [list(map(int, input().split())) for _ in range(N)] INF = 10 ** 18 dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)] for i in range(N + 1): for msk in range(8): dp[i][0][msk] = 0 for i in range(1, N + 1): x, y, z = cake[i - 1] ...
p03326
N, M = list(map(int, input().split())) cake = [list(map(int, input().split())) for _ in range(N)] INF = 10 ** 18 dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)] for i in range(N + 1): for msk in range(8): dp[i][0][msk] = 0 for i in range(1, N + 1): x, y, z = cake[i - 1] ...
N, M = list(map(int, input().split())) cake = [list(map(int, input().split())) for _ in range(N)] ans = [[] for _ in range(8)] for x, y, z in cake: for msk in range(8): mx = x * (1 - 2 * (msk >> 2 & 1)) my = y * (1 - 2 * (msk >> 1 & 1)) mz = z * (1 - 2 * (msk >> 0 & 1)) ans...
p03326
import sys N,M=list(map(int,input().split())) if M==0: print((0)) sys.exit(0) xyzlist=[] for i in range(N): x,y,z=list(map(int,input().split())) xyzlist.append((x,y,z)) #print(xyzlist) selected_list1=[False]*N pt_list=[0,0,0] for _ in range(M): max_ind=-1 max_point=-10**20 for i in ra...
import sys N,M=list(map(int,input().split())) xyzlist=[] for i in range(N): x,y,z=list(map(int,input().split())) xyzlist.append((x,y,z)) #print(xyzlist) answer=0 for b in range(2**3): bit=[0]*3 for i in range(3): bit[i]=b%2 b//=2 #print(bit) slist=[] for x,y,z in xyzlist...
p03326
n,m = [int(i) for i in input().split()] cakes = [] ranking = [[] for i in range(8)] ranking2 = [] for i in range(n): cakes.append(list(map(int,input().split()))) a = 0 for i in range(2): for j in range(2): for k in range(2): for x in range(n): kirei = cakes[x...
n,m = [int(i) for i in input().split()] ck = [] for i in range(n): ck.append(list(map(int,input().split()))) co1=co2=co3=-1 scores = [] maxi = 0 for i in range(2): co1 *= -1 for j in range(2): co2 *= -1 for k in range(2): co3*= -1 scores = [] ...
p03326
import itertools as it def f(c): x = abs(sum([i[0] for i in c])) y = abs(sum([i[1] for i in c])) z = abs(sum([i[2] for i in c])) return x + y + z N, M = tuple(map(int, input().split())) v = [[int(x) for x in input().split()] for j in range(N)] c = list(it.combinations(v, M)) print((max(f(x)...
N, M = tuple(map(int, input().split())) v = [[int(x) for x in input().split()] for j in range(N)] v2 = [[v[i][0]*p + v[i][1]*q + v[i][2]*r for i in range(N)] for p in [1, -1] for q in [1, -1] for r in [1, -1]] v3 = [sorted(v2[i], reverse=True) for i in range(8)] m = 0 for i in range(8): n = sum(v3[i][:M]) ...
p03326
# -*- coding: utf-8 -*- # AtCoder Beginner Contest if __name__ == '__main__': from itertools import product from heapq import nlargest n, m = list(map(int, input().split())) xyz = [list(map(int, input().split())) for i in range(n)] ans = 0 # See: # https://beta.atcoder.jp/co...
# -*- coding: utf-8 -*- def main(): from itertools import product n, m = list(map(int, input().split())) xyz = [list(map(int, input().split())) for _ in range(n)] ans = 0 for op1, op2, op3 in list(product([1, -1], repeat=3)): tmp = [[0, 0, 0]] * n for index, value i...
p03326
L=lambda:list(map(int,input().split()));r=range;n,m=L();k=[L()for _ in r(n)];print((max(-sum(sorted([-sum([j[i]*(int(bin(s)[2:].zfill(3)[i])*2-1)for i in r(3)])for j in k])[:m])for s in r(8))))
n,m=list(map(int,input().split())) xyz=[list(map(int,input().split()))for _ in range(n)] def f(fx,fy,fz): t=[] for x,y,z in xyz:t.append(x*fx+y*fy+z*fz) t.sort(reverse=1) return sum(t[:m]) ans=0 ans=max(ans,f(1,1,1)) ans=max(ans,f(1,1,-1)) ans=max(ans,f(1,-1,1)) ans=max(ans,f(1,-1,-1)) ans=max(ans,f...
p03326
N,M=list(map(int,input().split())) dp_ppp=[-1000000]*(N+1) dp_mpp=[-1000000]*(N+1) dp_pmp=[-1000000]*(N+1) dp_ppm=[-1000000]*(N+1) dp_mmp=[-1000000]*(N+1) dp_mpm=[-1000000]*(N+1) dp_pmm=[-1000000]*(N+1) dp_mmm=[-1000000]*(N+1) dp_ppp[0]=0 dp_mpp[0]=0 dp_pmp[0]=0 dp_ppm[0]=0 dp_mmp[0]=0 dp_mpm[0]=0 dp_pmm...
import sys input=sys.stdin.readline N,M=list(map(int,input().split())) dp_ppp=[] dp_mpp=[] dp_pmp=[] dp_ppm=[] dp_mmp=[] dp_mpm=[] dp_pmm=[] dp_mmm=[] for i in range(N): x,y,z=list(map(int,input().split())) dp_ppp.append(x+y+z) dp_mpp.append(-x+y+z) dp_pmp.append(x-y+z) dp_ppm.append(x+y-z) ...
p03326
#!/usr/bin/env python3 from itertools import product n, m = list(map(int, input().split())) xyz = [list(map(int, input().split())) for i in range(n)] dp = [[0 for i in range(m+1)] for j in range(n+1)] # eval # eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]", # "+xyz[i-1][0]+xyz[i-1][1]-xyz...
#!/usr/bin/env python3 from itertools import product n, m = list(map(int, input().split())) xyz = [list(map(int, input().split())) for i in range(n)] dp = [[0 for i in range(m+1)] for j in range(n+1)] # eval # eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]", # "+xyz[i-1][0]+xyz[i-1][1]-xyz...
p03326
n, m = list(map(int, input().split())) x = [] y = [] z = [] for i in range(n): X, Y, Z = list(map(int, input().split())) x.append(X) y.append(Y) z.append(Z) sign = [1, -1] ans = [] for j in sign: for k in sign: for l in sign: a = [] for i in r...
n, m = list(map(int, input().split())) cake = [list(map(int, input().split())) for i in range(n)] box = [[[[] for i in range(2)] for j in range(2)] for k in range(2)] ans = 0 for i in range(2): for j in range(2): for k in range(2): worth = 0 for x, y, z in cake: ...
p03326
import itertools N, M = list(map(int, input().split())) lst = [list(map(int, input().rstrip().split())) for n in range(N)] num = [i for i in range(N)] maximum = -float("inf") for p in itertools.combinations(num, M): m = sum(abs(sum(lst[n][i] for n in p)) for i in range(3)) maximum = max(maximum, m) ...
N, M = list(map(int, input().split())) lst = [list(map(int, input().rstrip().split())) for n in range(N)] maximum = -float("inf") for i in [-1, 1]: for j in [-1, 1]: for k in [-1, 1]: sum_lst = [] for n in range(N): num = lst[n][0] * i + lst[n][1] * j + lst[n]...
p03326
import itertools import sys input = sys.stdin.readline N, M = list(map(int, input().split())) cakes = [] for _ in range(N): x, y, z = list(map(int, input().split())) cakes.append((x, y, z)) ans = 0 for i in itertools.combinations(cakes, M): sx, sy, sz = 0, 0, 0 for j in i: x, y, z ...
N, M = list(map(int, input().split())) cakes = [] for _ in range(N): x, y, z = list(map(int, input().split())) cakes.append((x, y, z)) ans = 0 for i in range(2**3): op1, op2, op3 = 1, 1, 1 for idx, j in enumerate(bin(i)[2:][::-1], 1): j = int(j) if idx == 1: op1 ...
p03326
import sys sys.setrecursionlimit(50000) n,m=(int(i) for i in input().strip().split(" ")) xs=[] ys=[] zs=[] for i in range(n): a,b,c=(int(i) for i in input().strip().split(" ")) xs.append(a) ys.append(b) zs.append(c) def g(): return "no" from collections import defaultdict d=default...
import sys sys.setrecursionlimit(50000) n, m = (int(i) for i in input().strip().split(" ")) xs = [] ys = [] zs = [] for i in range(n): a, b, c = (int(i) for i in input().strip().split(" ")) xs.append(a) ys.append(b) zs.append(c) k=0 ar=[] for i in range(n): ar.append(xs[i]+ys[i...
p03326
import sys sys.setrecursionlimit(1000000000) N, M = list(map(int, input().split())) x, y, z = [], [], [] for _ in range(N): xyz = list(map(int, input().split())) x += [xyz[0]] y += [xyz[1]] z += [xyz[2]] def func(i, j, fx, fy, fz, v): if i > N - 1 or j > M - 1: return v ...
N, M = list(map(int, input().split())) xyz = [] ans = 0 for _ in range(N): xyz += [list(map(int, input().split()))] for b in range(2 ** 3): pm = [1] * 3 for j in range(3): if (b >> j) & 1: pm[j] *= -1 r = [] for i in range(N): r += [pm[0] * xyz[i][0] + pm[1] *...
p03326
from itertools import combinations N,M = list(map(int,input().split())) # <=1000 xyz = [list(map(int,input().split())) for _ in range(N)] x = [i[0] for i in xyz] y = [i[1] for i in xyz] z = [i[2] for i in xyz] if M == 0: print((0)) exit() result = 0 for s in combinations(list(range(N)),M): tx ...
import itertools N,M = list(map(int,input().split())) # <=1000 xyz = [list(map(int,input().split())) for _ in range(N)] if M == 0: print((0)) exit() result = 0 L = [[0] * N for i in range(8)] for i,j in enumerate(itertools.product((-1,1),repeat=3)): for k,l in enumerate(xyz): L[i][k] = ...
p03326
inf = float('inf') mod = 10**9+7 from itertools import product, permutations, combinations, combinations_with_replacement import bisect N, M = list(map(int, input().split())) xyz = [list(map(int, input().split())) for i in range(N)] result = -inf kireisa = 0 oishisa = 0 ninkido = 0 for i in combinat...
N, M = list(map(int, input().split())) xyz = [list(map(int, input().split())) for i in range(N)] tmp = [[0]*N for i in range(8)] for n, _ in enumerate(xyz): x,y,z = _ tmp[0][n] = x+y+z tmp[1][n] = x+y-z tmp[2][n] = x-y+z tmp[3][n] = x-y-z tmp[4][n] = -x+y+z tmp[5][n] = -x+y-z ...
p03326
n,m=list(map(int,input().split())) xyz=[list(map(int,input().split())) for _ in range(n)] t=[[0]*n for _ in range(8)] i=0 for x,y,z in xyz: t[0][i]=x+y+z t[1][i]=-x+y+z t[2][i]=x-y+z t[3][i]=x+y-z t[4][i]=-x-y+z t[5][i]=x-y-z t[6][i]=-x+y-z t[7][i]=-x-y-z i+=1 ans=0 fo...
n, m = list(map(int, input().split())) xyz = [list(map(int, input().split())) for _ in range(n)] if m==0: print((0)) exit() t = [[0] * n for _ in range(4)] i = 0 for x, y, z in xyz: t[0][i] = x + y + z t[1][i] = -x + y + z t[2][i] = x - y + z t[3][i] = x + y - z i += 1 ans = 0 ...
p03326
#ABC100-D Patisserie ABC """ +を採用するか-を採用するかで各評価値が2通りなので、 2**3の全探索を行えば良い """ import sys from copy import deepcopy from operator import itemgetter readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n,m = list(map(int,readline().split())) xyz = [] for i in range(n): xyz.append(l...
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n,m = list(map(int,readline().split())) lst1 = [] for i in range(n): lst1.append(list(map(int,readline().split()))) ans = 0 for i in range(1<<4): res = [0]*n for j in range(3): if i>>j&1: ...
p03326
N,M = list(map(int,input().split())) xs,ys,zs =[],[],[] comps1 = [] comps2 = [] comps3 = [] comps4 = [] comps5 = [] comps6 = [] comps7 = [] comps8 = [] for i in range(N): x,y,z = list(map(int,input().split())) raw = [x+y+z,x+y-z,x-y+z,x-y-z,-x+y+z,-x+y-z,-x-y+z,-x-y-z,] comps1.append(raw[0]) ...
N,M = list(map(int,input().split())) comp = [[] for _ in range(8)] for i in range(N): x,y,z = list(map(int,input().split())) raw = [x+y+z,x+y-z,x-y+z,x-y-z,-x+y+z,-x+y-z,-x-y+z,-x-y-z] for j in range(8): comp[j].append(raw[j]) ans = 0 for k in range(8): comp[k].sort(reverse=True) s...
p03326
n, m = list(map(int, input().split())) xyz = [tuple(map(int, input().split())) for _ in range(n)] def isum(i, x, y, z): s = 0 s += x if (i>>0)&1 else -x s += y if (i>>1)&1 else -y s += z if (i>>2)&1 else -z return s ans = 0 for i in range(2**3): dp = [0 for _ in range(m+1)] for k ...
n, m = list(map(int, input().split())) xyz = [tuple(map(int, input().split())) for _ in range(n)] ans = 0 from itertools import product for p in product([-1, 1], repeat=3): xyz_ = [l[0]*p[0] + l[1]*p[1] + l[2]*p[2] for l in xyz] xyz_ = sorted(xyz_, reverse=True) ans = max(ans, sum(xyz_[:m])) print(a...
p03326
N,M = list(map(int,input().split())) xyz = [list(map(int,input().split())) for _ in range(N)] ans = [[] for _ in range(8)] for x,y,z in xyz: for i in range(8): ans[i].append(x*((-1)**i)+y*((-1)**(i//2))+z*((-1)**(i//4))) out = [] for i in range(8): ans[i].sort(reverse=True) out.append(sum(a...
N,M = list(map(int,input().split())) XYZ = [list(map(int,input().split())) for _ in [0]*N] W = [[0]*N for _ in [0]*4] for i,xyz in enumerate(XYZ): x,y,z = xyz W[0][i] = x+y+z W[1][i] = x+y-z W[2][i] = x-y+z W[3][i] = x-y-z ans = 0 for i in range(4): W[i].sort() ans = max(ans, ...
p03326
import functools [N, M] = [int(x) for x in input().split()] XYZ = [] for i in range(N): XYZ.append([int(x) for x in input().split()]) result = 0 for x in range(-1, 2, 2): for y in range(-1, 2, 2): for z in range(-1, 2, 2): contribute = [x, y, z] score = [functools.reduce(lambda a, b: a + b...
N, M = list(map(int, input().split())) Cakes = [[] for i in range(N)] for i in range(N): Cakes[i] = [int(x) for x in input().split()] ans = 0 for s in range(8): sx = 1 if s % 2 else -1 sy = 1 if s // 2 % 2 else -1 sz = 1 if s // 4 % 2 else -1 ans = max(sum(sorted([sx * x + sy * y + sz * z for x, y, z...
p03326
# coding: utf-8 n, m = [int(x) for x in input().split()] xx = [] yy = [] zz = [] for _ in range(n): x, y, z = [int(x) for x in input().split()] xx.append(x) yy.append(y) zz.append(z) result_points = [] for k in range(8): max_point = 0 selected_indexes = [] for i in rang...
# coding: utf-8 n, m = [int(x) for x in input().split()] xx = [] yy = [] zz = [] for _ in range(n): x, y, z = [int(x) for x in input().split()] xx.append(x) yy.append(y) zz.append(z) result_points = [] results = [] for i in range(8): results.append([]) for j in range(n): ...
p03326
import itertools N, M = list(map(int, input().split())) l = [list(map(int, input().split())) for _ in range(N)] r = 0 for c in itertools.combinations(l, M): s = sum(abs(sum(v[i] for v in c)) for i in range(3)) if s > r: r = s print(r)
N, M = list(map(int, input().split())) l = [list(map(int, input().split())) for _ in range(N)] a = 0 for xs in (1, -1): for ys in (1, -1): for zs in (1, -1): l_s = [x*xs + y*ys + z*zs for x, y, z in l] l_s.sort(reverse=True) a = max(sum(l_s[:M]), a) print(a)
p03326
from itertools import combinations def score (cids): x = abs(sum(data[cid][0] for cid in cids)) y = abs(sum(data[cid][1] for cid in cids)) z = abs(sum(data[cid][2] for cid in cids)) return x + y + z n, m = list(map(int, input().split())) data = list([int(x) for x in input().split()] for _ in ...
n, m = list(map(int, input().split())) data = [[int(x) for x in input().split()] for _ in range(n)] pats = [(x,y,z) for x in [-1,1] for y in [-1,1] for z in [-1,1]] # +++,++-,...,--- score = lambda sgns, vals: sum([s * x for(s, x) in zip(sgns, vals)]) # i.e.x+y-z result = max(sum(sorted((score(pat, row) for row ...
p03326
N, M = list(map(int, input().split())) cakes = [] for _ in range(N): cakes.append(list(map(int, input().split()))) memo = dict() def pick_cake(picked): key = ','.join([str(p) for p in sorted(picked)]) if key in memo: return memo[key] if len(picked) == M: memo[key] = sum...
from itertools import product N, M = list(map(int, input().split())) cakes = [] for _ in range(N): cakes.append(list(map(int, input().split()))) def _eval1(op): def _eval2(x): return eval(''.join(['{}{}'.format(op[i], x[i]) for i in range(3)])) return _eval2 answer = 0 for op in ...
p03326
N,M=list(map(int,input().split())) xyz=[list(map(int,input().split()))for i in range(N)] ans=0 for i in range(8): i=bin(i)[2:].zfill(3) k=[] for j in range(3): if i[j]=="0": k.append(1) else: k.append(-1) l=[k[0]*x+k[1]*y+k[2]*z for x,y,z in xyz] l...
N,M=list(map(int,input().split())) xyz=[] for i in range(N): x,y,z=list(map(int,input().split())) xyz.append([x,y,z]) ans=0 for k in range(8): A=[k>>2 &1,k>>1 &1,k>>0 &1] l=[] for i in range(N): t=0 for j in range(3): if A[j]==0: t+=xyz[i][j] ...
p03326
import itertools if __name__ == '__main__': n,m = list(map(int,input().split())) A =[] for i in range(n): A.append(list(map(int,input().split()))) maxval = 0 for v in itertools.combinations(A,m): a = abs(sum(list([x[0] for x in v]))) b = abs(sum(list([x[1] for x in v]))) c = abs(sum(list(...
import itertools if __name__ == '__main__': n,m = list(map(int,input().split())) A =[] for i in range(n): A.append(list(map(int,input().split()))) P = list(itertools.product([1,-1],repeat=3)) maxval = 0 for p in P: B=[] for a in A: val = (a[0] * p[0]) + (a[1] * p[1]) + (a[2] * p[2]...
p03326
#おわり、むり N,W = list(map(int,input().split())) X,Y,Z = [],[],[] for i in range(N): x,y,z = list(map(int,input().split())) X.append(x) Y.append(y) Z.append(z) dp = [[[0,0,0] for i in range(W+1)] for j in range(N+1)] for i in range(W+1): dp[0][i][0]= 0 #X dp[0][i][1]= 0 #Y ...
N,W = list(map(int,input().split())) L = [] for i in range(N): L.append(list(map(int,input().split()))) MAX_ANS = 0 for fgo in range(0,8): FGO = [pow(-1,fgo%2),pow(-1,(fgo//2)%2),pow(-1,(fgo//4)%2)] L = sorted(L,key=lambda x:x[0]*FGO[0]+x[1]*FGO[1]+x[2]*FGO[2],reverse=True) ans = 0 ...
p03326
import itertools [N,M]=list(map(int,input().split() ) ) XYZ=[[int(i) for i in input().split()] for i in range(N)] maxabs=0 for indextupl in list(itertools.permutations(list(range(N)), M)): maxabs=max(sum([abs(sum([XYZ[i][j] for i in indextupl])) for j in range(3)]), max...
[N,M]=list(map(int,input().split() ) ) XYZ=[[int(i) for i in input().split()] for i in range(N)] maxabs=0 for i in range(8): pm=list(map(int,format(i, 'b'))) pm=[0,]*(3-len(pm))+pm pm=[(-1)**item for item in pm] newXYZ=sorted([[item[0]*pm[0],item[1]*pm[1],item[2]*pm[2]] f...
p03326
import itertools def resolve(): n,m=list(map(int,input().split())) l=[] for i in range(n): x,y,z=list(map(int,input().split())) l.append([x,y,z]) lst=list(itertools.combinations(l,m)) ms=0 for i in lst: xx=abs(sum([p[0] for p in i])) yy=abs(sum([p[1] for p in i])) zz=abs(sum([p[2] for p ...
def resolve(): ans=0 n,m=list(map(int,input().split())) xyz=[list(map(int,input().split())) for i in range(n)] t=[(1,1,1),(1,1,-1),(1,-1,1),(1,-1,-1),(-1,1,1),(-1,1,-1),(-1,-1,1),(-1,-1,-1)] for k in t: l=[k[0]*x+k[1]*y+k[2]*z for x,y,z in xyz ] l.sort(reverse=True) ans=max(ans,sum(l[:m])) print(an...
p03326
N,M = list(map(int, input().split())) xs,ys,zs = [], [], [] """ sum000 +++ sum001 ++- sum010 +-+ sum011 +-- sum100 -++ sum101 -+- sum110 --+ sum111 --- """ sum000, sum001, sum010,sum011 = [], [], [], [] sum100, sum101, sum110,sum111 = [], [], [], [] sums = [[] for i in range(8)] for i in range(N): ...
N,M = list(map(int, input().split())) """ xyz 0+++ 1++- 2+-+ 3+-- 4-++ 5-+- 6--+ 7--- """ dp = [[0]*N for i in range(8)] for i in range(N): x,y,z = list(map(int, input().split())) dp[0][i] = x+y+z dp[1][i] = x+y-z dp[2][i] = x-y+z dp[3][i] = x-y-z dp[4][i] = -x+y+z ...
p03326
import itertools N,M=list(map(int,input().split())) x=[0 for i in range(N)] y=[0 for i in range(N)] z=[0 for i in range(N)] for i in range(N): x[i],y[i],z[i]=list(map(int,input().split())) w=[[0 for i in range(N)] for i in range(8)] S=list(itertools.product([-1,1],repeat=3)) def num(inp): res=0 f...
import itertools N,M=list(map(int,input().split())) x=[0 for i in range(N)] y=[0 for i in range(N)] z=[0 for i in range(N)] for i in range(N): x[i],y[i],z[i]=list(map(int,input().split())) S=list(itertools.product([-1,1],repeat=3)) def num(seq): res=0 for i in range(3): if seq[i]==1: ...
p03326
from itertools import combinations def inpl(): return input().split() n, m = list(map(int, inpl())) M = [] for i in range(n): M.append(list(map(int, inpl()))) cake_sets = combinations(M, m) ans = -1 for c_set in cake_sets: val = 0 for typ in range(3):#x, y, z t_val = 0 for ...
N, M = list(map(int, input().split())) XYZs = [list(map(int, input().split())) for _ in range(N)] ans = 0 for op in range(1 << 3): lst = [] for xyz in XYZs: v = 0 for j in range(3): v += xyz[j] * ((-1) ** ((op >> j) & 1)) lst.append(v) ans = max(ans, sum(sorte...
p03326
N, M = list(map(int, input().split())) XYZs = [list(map(int, input().split())) for _ in range(N)] ans = 0 for op in range(1 << 3): lst = [] for xyz in XYZs: v = 0 for j in range(3): v += xyz[j] * ((-1) ** ((op >> j) & 1)) lst.append(v) ans = max(ans, sum(sorte...
N, M = list(map(int, input().split())) XYZs = [tuple(map(int, input().split())) for _ in range(N)] ans = 0 for i in range(1 << 3): signs = [] for j in range(3): if i >> j & 1: signs.append(1) else: signs.append(-1) t = [] for xyz in XYZs: x, ...
p03326
import itertools n = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(n[0])] c = n[0] d = n[1] e = [0+i for i in range(c)] f = list(itertools.combinations(e, d)) ans = [] for i in f: x, y, z = (0, 0, 0) for j in i: g = a[j] x, y, z = (x + g[0]...
n = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(n[0])] c = n[0] d = n[1] e = [1, -1] f = [] for i in e: for j in e: for k in e: f.append([i,j,k]) ans = [] for i in f: g = [] for j in a: g.append(sum([j[k]*i[k] for k in range(...
p03326
n,m = list(map(int,input().split())) bit = [bin(i)[2:].zfill(3) for i in range(2**m)] ans = -int(1e10) cake = [] for i in range(n): a,b,c = list(map(int,input().split())) cake.append((a,b,c)) for i in range(2**m): u = [] cond = bit[i] for j in range(n): cnt = 0 for k in r...
n,m = list(map(int,input().split())) bit = [bin(i)[2:].zfill(3) for i in range(2**3)] ans = -int(1e10) cake = [] for i in range(n): a,b,c = list(map(int,input().split())) cake.append((a,b,c)) for i in range(2**3): u = [] cond = bit[i] for j in range(n): cnt = 0 for k in r...
p03326
from itertools import product INF = 10**18 N, M = list(map(int, input().split())) XYZ = [list(map(int, input().split())) for _ in range(N)] # i番目までのケーキの内、j個食べた時のpointの最大値 # (ただしpointの計算時には、8通りのmaskを乗算する) def mul_mask(l, mask): return [a*b for a, b in zip(l, mask)] dp_std = [[-INF for _ in range(M+...
# from itertools import product INF = 10**18 N, M = list(map(int, input().split())) XYZ = [list(map(int, input().split())) for _ in range(N)] # i番目までのケーキの内、j個食べた時のpointの最大値 # (ただしpointの計算時には、8通りのmaskを乗算する) def mul_mask(l, mask): p = [] for i, m in enumerate(l): p.append(m*mask[i]) ...
p03326
import itertools def main(): # 8通りの方法を調べて最大値 -,-,- から +,+,+ N, M = list(map(int, input().split())) data = [[0] * 8 for _ in range(M+1)] p = list(itertools.product([-1, 1], repeat=3)) for i in range(N): #print(data) x, y, z = list(map(int, input().split())) for ...
import itertools def main(): # 8通りの方法を調べて最大値 -,-,- から +,+,+ N, M = list(map(int, input().split())) data = [[] for i in range(8)] p = list(itertools.product([-1, 1], repeat=3)) for i in range(N): #print(data) x, y, z = list(map(int, input().split())) for j in ra...
p03326
# https://atcoder.jp/contests/abc100/tasks/abc100_d from itertools import product N, M, *XYZ = list(map(int, open(0).read().split())) P = tuple(product((1, -1), repeat=3)) A = [[] for _ in range(8)] for x, y, z in zip(*[iter(XYZ)] * 3): for i, (a, b, c) in enumerate(P): A[i].append(a * x + b ...
N, M, *XYZ = list(map(int, open(0).read().split())) A = [[] for _ in range(8)] for x, y, z in zip(*[iter(XYZ)] * 3): A[0].append(sum((x, y, z))) A[1].append(sum((x, y, -z))) A[2].append(sum((x, -y, z))) A[3].append(sum((x, -y, -z))) A[4].append(sum((-x, y, z))) A[5].append(sum((-x, y, ...
p03326
import sys input = sys.stdin.readline n, m = [int(x) for x in input().split()] xyz = [[int(x) for x in input().split()] for _ in range(n)] dp = [[[0, 0, 0] for _ in range(n + 1)] for _ in range(n)] for i in range(n): for j in range(1, i + 2): if i != 0: dp[i][j] = dp[i - 1][j] ...
import sys input = sys.stdin.readline n, m = [int(x) for x in input().split()] xyz = [[int(x) for x in input().split()] for _ in range(n)] ans = 0 for i in range(8): i_bin = bin(i)[2:].zfill(3) new_xyz_sum = [] for j in range(n): tmp = 0 x, y, z = xyz[j] if i_bin[0] ...
p03326
#!/usr/bin/env python # -*- coding: utf-8 -*- from queue import Queue def solve(): n, m = list(map(int, input().split())) al = [[int(i) for i in input().split()] for _ in range(n)] ans = 0 q = Queue() for i in range(n): tq = Queue() while not q.empty(): e...
n, m = list(map(int, input().split())) l = [[int(i) for i in input().split()] for _ in [0]*n] ans = 0 def getmm(k): f = lambda x: (x[0] if k & 1 else -x[0]) + (x[1] if k & 2 else -x[1]) + (x[2] if k & 4 else -x[2]) al = [f(e) for e in l] al.sort(reverse=True) return sum(al[:m]) for i in range(8): ...
p03326
N,M=list(map(int,input().split())) L=[] for i in range(N): x,y,z=list(map(int,input().split())) L.append([x,y,z]) A=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]] ans=-1000000000000 B=[] for i in range(8): for j in range(N): B.append(A[i][0]*L[j][0]+A[i...
N,M=list(map(int,input().split())) LPPP=[] LPPM=[] LPMP=[] LPMM=[] LMPP=[] LMPM=[] LMMP=[] LMMM=[] for i in range(N): x,y,z=list(map(int,input().split())) LPPP.append(x+y+z) LPPM.append(x+y-z) LPMP.append(x-y+z) LPMM.append(x-y-z) LMPP.append(-x+y+z) LMPM.append(-x+y-z) ...
p03326
# -*- coding: utf-8 -*- n,m = list(map(int, input().split())) xyz = [] for _ in range(n): line = list(map(int, input().split())) xyz.append(line) score = -1 for xo in [1,-1]: for yo in [1,-1]: for zo in [1,-1]: idx = sorted(list(range(n)), reverse=True, key=lambda i:xo*xyz[i]...
# -*- coding: utf-8 -*- n,m = list(map(int, input().split())) xyz = [list(map(int, input().split())) for _ in range(n)] res = -1 for xi in [1,-1]: for yi in [1,-1]: for zi in [1,-1]: xyz.sort(reverse=True, key=lambda c:c[0]*xi+c[1]*yi+c[2]*zi) t = [0,0,0] for i...
p03326
N,M=list(map(int,input().split())) cake=[list(map(int,input().split()))for _ in[0]*N] dp=[[[0]*3]for _ in[0]*(M+1)] for c in cake: for i in range(M-1,-1,-1): for t in dp[i]: dp[i+1]+=[[c[i]+t[i]for i in range(3)]] if len(dp[i])>10: a=[sum(t)for t in dp[i]] ...
N,M=list(map(int,input().split())) sums=[[]for _ in[0]*8] for _ in[0]*N: c=list(map(int,input().split())) for t in range(8): sums[t]+=[sum(c[i]*[-1,1][t&(1<<i)>0]for i in range(3))] if M:print((max(sum(sorted(sums[i])[-M:])for i in range(8)))) else:print((0))
p03326
import copy n,m = list(map(int,input().split())) scores = list() for i in range(n): score = list(map(int,input().split())) scores.append(score) smax=None for i in range(n): scores_ = copy.deepcopy(scores) for j in range(len(scores[i])): if scores[i][j]<0: for k in ...
import copy n,m = list(map(int,input().split())) #取得 scores = list() for i in range(n): score = list(map(int,input().split())) scores.append(score) smax=None for x in range(2): scores_=copy.deepcopy(scores) for i in range(n): scores_[i][0] = pow(-1,x)*scores[i][0] for y...
p03326
N,M=list(map(int,input().split())) cakes=[] for i in range(N): x,y,z=list(map(int,input().split())) cakes.append([x,y,z]) if M==0: print((0)) quit() score=[0]*8 score[0]=sum(sorted([c[0]+c[1]+c[2] for c in cakes])[-M:]) score[1]=sum(sorted([c[0]+c[1]-c[2] for c in cakes])[-M:]) score[2]=sum(sorted([c...
N,M=list(map(int,input().split())) cakes=[] for i in range(N): x,y,z=list(map(int,input().split())) cakes.append([x,y,z]) if M==0: print((0)) quit() score=[0]*8 s=sorted([c[0]+c[1]+c[2] for c in cakes]) score[0]=sum(s[-M:]) score[1]=-sum(s[:M]) s=sorted([c[0]+c[1]-c[2] for c in cakes]) score[2]=sum...
p03326
import itertools n,m = list(map(int,input().split())) lst = [list(map(int,input().split())) for _ in range(n)] res = 0 for l in itertools.permutations(lst, m): X,Y,Z = 0,0,0 for i in range(m): x,y,z = l[i][0], l[i][1], l[i][2] X += x Y += y Z += z res = max(res, ab...
n,m = list(map(int,input().split())) lst0, lst1, lst2, lst3, lst4, lst5, lst6, lst7 =[],[],[],[],[],[],[],[] for i in range(n): x,y,z = list(map(int,input().split())) lst0.append(x+y+z) lst1.append(x+y-z) lst2.append(x-y+z) lst3.append(x-y-z) lst4.append(-x+y+z) lst5.append(-x+y-z) ...
p03326
n,m = list(map(int,input().split())) lst0, lst1, lst2, lst3, lst4, lst5, lst6, lst7 =[],[],[],[],[],[],[],[] for i in range(n): x,y,z = list(map(int,input().split())) lst0.append(x+y+z) lst1.append(x+y-z) lst2.append(x-y+z) lst3.append(x-y-z) lst4.append(-x+y+z) lst5.append(-x+y-z) ...
n,m = list(map(int,input().split())) lst = [[] for _ in range(8)] for i in range(n): x,y,z = list(map(int,input().split())) lst[0].append(x+y+z) lst[1].append(x+y-z) lst[2].append(x-y+z) lst[3].append(x-y-z) lst[4].append(-x+y+z) lst[5].append(-x+y-z) lst[6].append(-x-y+z) ...
p03326
N, M = list(map(int, input().split())) XYZ = [list(map(int, input().split())) for i in range(N)] X = [XYZ[i][0] for i in range(N)] Y = [XYZ[i][1] for i in range(N)] Z = [XYZ[i][2] for i in range(N)] ans = 0 for i in range(2**M - 1, 2**N - 2**(N - M) + 1): b = bin(i)[2:] if len(b) != N: f = [0...
N, M = list(map(int, input().split())) cakes = [] for i in range(N): x, y, z = list(map(int, input().split())) cakes.append([x, y, z]) if M == 0: print((0)) quit() score = [0]*8 s = sorted([c[0]+c[1]+c[2] for c in cakes]) score[0] = sum(s[-M:]) score[1] = -sum(s[:M]) s = sorted([c[0]+c[1...
p03326
import itertools n, m = list(map(int, (input().split()))) scores = [list(map(int,input().split())) for _ in range(n) ] max_socre = 0 for cakes in itertools.combinations(scores, m): b = 0 t = 0 p = 0 for cake in cakes: b += cake[0] t += cake[1] p += cake[2] ...
import itertools n, m = list(map(int, (input().split()))) scores = [list(map(int,input().split())) for _ in range(n) ] # 8 pattern max_of_sum = 0 for pick in range(8): sum_scores = [] for score in scores: sum_of_score = 0 if pick & 0b001 == 0: # plus ...
p03326
import sys import heapq, math from itertools import zip_longest, permutations, combinations, combinations_with_replacement from itertools import accumulate, dropwhile, takewhile, groupby from functools import lru_cache from copy import deepcopy N, M = list(map(int, input().split())) X, Y, Z = [0] * N, [0] * N,...
import sys import heapq, math from itertools import zip_longest, permutations, combinations, combinations_with_replacement from itertools import accumulate, dropwhile, takewhile, groupby from functools import lru_cache from copy import deepcopy N, M = list(map(int, input().split())) X, Y, Z = [0] * N, [0] * N,...
p03326
n,m = list(map(int,input().split())) xyz = [list(map(int,input().split())) for i in range(n)] dp = [[[[0,0,0] for k in range(8)] for j in range(n+1)] for i in range(n+1)] for i in range(n): for j in range(1,i+2): for k in range(8): l,r = 0,0 for d in range(3): ...
n,m = list(map(int,input().split())) xyz = [list(map(int,input().split())) for i in range(n)] ans = 0 for i in range(8): s = [] for j in range(n): a = 0 for k in range(3): if i>>k&1: a += xyz[j][k] else: a -= xyz[j][k] s...
p03326
N,M = list(map(int,input().split())) XYZ = [tuple(map(int,input().split())) for _ in range(N)] ans = 0 for b in range(8): dp = [0] for x,y,z in XYZ: if b&1: x *= -1 if b&2: y *= -1 if b&4: z *= -1 v = x+y+z dp2 = dp[:] for i in range(len(dp)-1,-1,-1): if i < M: if i+1 >= len(dp2): ...
N,M = list(map(int,input().split())) XYZ = [tuple(map(int,input().split())) for _ in range(N)] ans = 0 for b in range(8): arr = [] for x,y,z in XYZ: if b&1: x *= -1 if b&2: y *= -1 if b&4: z *= -1 arr.append(x+y+z) arr.sort(reverse=True) ans = max(ans, sum(arr[:M])) print(ans)
p03326
# -*- coding: utf-8 -*- n, m = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(n)] ans = 0 dp = [[0 for j in range(m+1)] for i in range(n+1)] for i in range(1, n+1): for j in range(1, m+1): dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]+A[i-1][0]+A[i-1][1]+A[i-1][2]) ...
# -*- coding: utf-8 -*- n, m = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(8): value_list = [] for a in A: value_list.append((2*(i&1)-1)*a[0] + (2*((i>>1)&1)-1)*a[1] + (2*((i>>2)&1)-1)*a[2]) value_list.sort(reverse=True) ...
p03326