1742
Codeforces Round 827 (Div. 4)
t = int ( input ())
for _ in range ( t ):
arr = list ( map ( int , input () . split ()))
arr . sort ()
if arr [ 0 ] + arr [ 1 ] == arr [ 2 ]:
print ( "YES" )
else :
print ( "NO" )
t = int ( input ())
for _ in range ( t ):
n = int ( input ())
arr = list ( map ( int , input () . split ()))
print ( "YES" if len ( set ( arr )) == n else "NO" )
t = int ( input ())
for _ in range ( t ):
input ()
grid = [ input () for _ in range ( 8 )]
for row in grid :
if all ( c == "R" for c in row ):
print ( "R" )
break
else :
print ( "B" )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import math
t = int ( input ())
for _ in range ( t ):
n = int ( input ())
s = list ( map ( int , input () . split ()))
ss = [ - 1 ] * 1001
for i in range ( n ):
ss [ s [ i ]] = i
res = - 1
for i in range ( 1 , 1001 ):
if ss [ i ] == - 1 :
continue
for j in range ( i , 1001 ):
if ss [ j ] != - 1 and math . gcd ( i , j ) == 1 :
res = max ( res , ss [ i ] + ss [ j ] + 2 )
print ( res )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from bisect import bisect
t = int ( input ())
for _ in range ( t ):
n , q = map ( int , input () . split ())
input_numbers = list ( map ( int , input () . split ()))
arr = [ 0 ] + input_numbers + [ 1e9 + 7 ] # 1000000007
b = list ( map ( int , input () . split ()))
_arr = arr . copy ()
for i in range ( 1 , n + 2 ):
_arr [ i ] += _arr [ i - 1 ]
arr [ i ] = max ( arr [ i ], arr [ i - 1 ])
for i in range ( q ):
b [ i ] = _arr [ bisect ( arr , b [ i ]) - 1 ]
print ( " " . join ( map ( str , b )))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 t = int ( input ())
def lower ( x , y ):
if any ( yi > 0 for yi in y [ 98 :]):
return True
if x [ 97 ] < y [ 97 ] and all ( xi == 0 for xi in x [ 98 :]):
return True
return False
for _ in range ( t ):
q = int ( input ())
s = [ 0 ] * 128
t = [ 0 ] * 128
s [ ord ( "a" )] = 1
t [ ord ( "a" )] = 1
for _ in range ( q ):
d , k , x = input () . split ()
d , k = int ( d ), int ( k )
if d == 1 :
for c in x :
s [ ord ( c )] += k
else :
for c in x :
t [ ord ( c )] += k
print ( "YES" if lower ( s , t ) else "NO" )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 t = int ( input ())
for _ in range ( t ):
n = int ( input ())
a = list ( map ( int , input () . split ()))
res = []
vis = 0
while a :
# Find the index of the element with the highest bitwise AND with the complement of visited
idx = max ( range ( len ( a )), key = lambda i : a [ i ] & ~ vis )
if not a [ idx ] & ~ vis :
break
res . append ( a . pop ( idx ))
vis |= res [ - 1 ]
res . extend ( a )
print ( " " . join ( str ( x ) for x in res ))