File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n = int (input ())
6+ a = sorted (list (map (int , input ().split ())))
7+ x = int (input ())
8+
9+ i , j = 0 , n - 1
10+ cnt = 0
11+ while i < j :
12+ total = a [i ] + a [j ]
13+ if total == x :
14+ cnt += 1
15+ i += 1
16+ j -= 1
17+ elif total > x :
18+ j -= 1
19+ else :
20+ i += 1
21+
22+ print (cnt )
Original file line number Diff line number Diff line change 1+ import sys
2+ from itertools import *
3+
4+ input = sys .stdin .readline
5+
6+ n , m = map (int , input ().split ())
7+ arr = list (i for i in range (1 , n + 1 ))
8+
9+ for comb in combinations (arr , m ):
10+ print (* comb )
Original file line number Diff line number Diff line change 1+ from collections import *
2+
3+
4+ def solution (n , computers ):
5+ answer = 0
6+ visited = [0 ] * (n + 1 )
7+
8+ def dfs (x ):
9+ visited [x ] = 1
10+ for i in range (n ):
11+ if not visited [i ] and computers [x ][i ] == 1 :
12+ dfs (i )
13+
14+ for i in range (n ):
15+ if not visited [i ]:
16+ dfs (i )
17+ answer += 1
18+
19+ return answer
You can’t perform that action at this time.
0 commit comments