-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc271_c.py
More file actions
128 lines (116 loc) · 2.92 KB
/
abc271_c.py
File metadata and controls
128 lines (116 loc) · 2.92 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
[tky]
from sortedcontainers import SortedSet
N=int(input())
A=list(map(int,input().split()))
B=SortedSet()
rem=0
for a in A:
if a in B:rem+=1
else:B.add(a)
ans=1
while 1:
if ans in B:
B.pop(0)
ans+=1
else:
if rem>=2:
rem-=2
ans+=1
elif rem==1:
rem=0
if len(B)>0:
B.pop(-1)
ans+=1
else:
break
elif len(B)>=2:
B.pop(-1)
B.pop(-1)
ans+=1
else:
break
print(ans-1)
###############################################
###############################################
###############################################
###############################################
###############################################
[nami]
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
cnt = 0
st = set()
for i in range(n):
if a[i] not in st:
st.add(a[i])
else:
cnt += 1
tmp = cnt % 2
cnt //= 2
a = list(set(a))
a = sorted(a)
ans = 0
i = 0
while i < len(a):
if a[i] == ans + 1:
i += 1
ans += 1
else:
if cnt > 0:
cnt -= 1
ans += 1
else:
if tmp == 1:
a.pop()
tmp = 0
ans += 1
else:
if len(a) - i >= 2:
a.pop()
a.pop()
ans += 1
else:
break
print(ans + cnt)
###############################################
###############################################
###############################################
[pt]
N = int(input())
a = list(map(int, input().split()))
a.sort()
B = set(a)
count = 0
while(N > 0):
if count+1 in B:
count+=1
N -= 1
else:
if 2 <= N:
count += 1
N -= 2
elif N == 1:
break
print(count)
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################