File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ n = int (input ())
2+
3+ arr = []
4+
5+ for i in range (n ):
6+ arr .append (int (input ()))
7+
8+ arr .sort ()
9+
10+ start = 0
11+ end = 0
12+
13+ max = float ("-inf" )
14+
15+ while end < n :
16+ if arr [end ] - arr [start ] > 4 :
17+ start += 1
18+ else :
19+ if end - start + 1 > max :
20+ max = end - start + 1
21+ end += 1
22+
23+ print (5 - max )
Original file line number Diff line number Diff line change 1+ n , m = map (int , input ().split ())
2+ arr = list (map (int , input ().split ()))
3+
4+ answer = 0
5+
6+ start = 0
7+ end = 0
8+
9+ cum_sum = arr [start ]
10+
11+ while end < len (arr ):
12+ if cum_sum == m :
13+ answer += 1
14+ cum_sum -= arr [start ]
15+ start += 1
16+ elif cum_sum < m :
17+ end += 1
18+ if end < len (arr ):
19+ cum_sum += arr [end ]
20+ else :
21+ cum_sum -= arr [start ]
22+ start += 1
23+
24+ print (answer )
Original file line number Diff line number Diff line change 1+ from functools import cmp_to_key
2+
3+ def max_num (a , b ):
4+ if a + b > b + a :
5+ return - 1
6+ elif b + a > a + b :
7+ return 1
8+ return 0
9+
10+ def solution (numbers ):
11+ sarr = list (map (str , numbers ))
12+
13+ # 정렬 기준: 두 수를 이어붙였을 때 큰 순서대로 정렬
14+ sarr .sort (key = cmp_to_key (max_num ))
15+
16+ # 만약 가장 큰 숫자가 0이면 전체가 0이므로 '0' 반환
17+ if sarr [0 ] == "0" :
18+ return "0"
19+
20+ return "" .join (sarr )
You can’t perform that action at this time.
0 commit comments