回答編集履歴
2
訂正
test
CHANGED
@@ -22,9 +22,9 @@
|
|
22
22
|
|
23
23
|
a = [0]*(ord("z")+1)
|
24
24
|
|
25
|
-
for i in
|
25
|
+
for i in s:
|
26
26
|
|
27
|
-
a[ord(
|
27
|
+
a[ord(i)] += 1
|
28
28
|
|
29
29
|
|
30
30
|
|
@@ -44,13 +44,13 @@
|
|
44
44
|
|
45
45
|
ans = ""
|
46
46
|
|
47
|
-
for i in
|
47
|
+
for i in s:
|
48
48
|
|
49
|
-
e = ord(
|
49
|
+
e = ord(i)
|
50
50
|
|
51
51
|
if e > c:
|
52
52
|
|
53
|
-
ans +=
|
53
|
+
ans += i
|
54
54
|
|
55
55
|
elif e == c:
|
56
56
|
|
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
else:
|
62
62
|
|
63
|
-
ans +=
|
63
|
+
ans += i
|
64
64
|
|
65
65
|
print(ans)
|
66
66
|
|
1
追記
test
CHANGED
@@ -5,3 +5,63 @@
|
|
5
5
|
こういうツールを使います。
|
6
6
|
|
7
7
|
[Python プロファイラ — Python 3.10.0b2 ドキュメント](https://docs.python.org/ja/3/library/profile.html)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#追記
|
12
|
+
|
13
|
+
違う考え方でのコード。
|
14
|
+
|
15
|
+
```Python
|
16
|
+
|
17
|
+
n, k = map(int, input().split())
|
18
|
+
|
19
|
+
s = list(str(input()))
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
a = [0]*(ord("z")+1)
|
24
|
+
|
25
|
+
for i in range(n):
|
26
|
+
|
27
|
+
a[ord(s[i])] += 1
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
b = 0
|
32
|
+
|
33
|
+
for c in range(ord("a"),ord("z")+1):
|
34
|
+
|
35
|
+
b += a[c]
|
36
|
+
|
37
|
+
if b >= k:
|
38
|
+
|
39
|
+
break
|
40
|
+
|
41
|
+
d = a[c]-(b-k)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
ans = ""
|
46
|
+
|
47
|
+
for i in range(n):
|
48
|
+
|
49
|
+
e = ord(s[i])
|
50
|
+
|
51
|
+
if e > c:
|
52
|
+
|
53
|
+
ans += s[i]
|
54
|
+
|
55
|
+
elif e == c:
|
56
|
+
|
57
|
+
if d > 0:
|
58
|
+
|
59
|
+
d -= 1
|
60
|
+
|
61
|
+
else:
|
62
|
+
|
63
|
+
ans += s[i]
|
64
|
+
|
65
|
+
print(ans)
|
66
|
+
|
67
|
+
```
|