python
n=int(input())
s="2026"
for i in range(1,n+1):
line=""
for j in range(i):
line+=s[j%4]
print(line)

python
n,k=map(int,input().split())
s=input().strip()
stack=[]
for c in s:
while k>0 and stack and stack[-1]<c:
stack.pop()
k-=1
stack.append(c)
if k>0:
stack=stack[:-k]
res=''.join(stack).lstrip('0')
print(res if res else'0')

python
m, a = map(int, input().split())
# 递归:day = 当前天数,x = 第day-1项,y = 第day项
def dfs(day, x, y):
# 先判断今天达不达标
if y % m == a:
return day
# 出现 1,1 循环,永远找不到
if x == 1 and y == 1 and day > 2:
return -1
# 递归下一天
return dfs(day + 1, y, (x + y) % m)
# 初始:第1天=1,第2天=1,从第2天开始查
print(dfs(2, 1, 1))

python
import heapq
n=int(input())
levels=[]
for _ in range(n):
a,b=map(int,input().split())
levels.append(a,b)
levels.sort()
heap=[]
total=0
for b,a in levels:
heapq.heappush(heap,-a)
total+=a
if total>b:
total-=(-heapq.heappop(heap))
print(len(heap))
python
heapq.heappush(heap, a) # 原始写法(小根堆)
heapq.heappush(heap, -a)
max_a = max(heap) # 原始写法(暴力找最大,慢)
-heap[0]因为堆顶是 最小负数 → 取反就是 最大正数。
-heapq.heappop(heap)
python
n = int(input())
levels = []
# 1. 读入所有关卡
for i in range(n):
a, b = map(int, input().split())
levels.append((a, b))
# 2. 贪心排序:按 b 从小到大排(核心!限制严的先打)
levels.sort(key=lambda x: x[1])
sum_a = 0 # 当前总体力
count = 0 # 答案:打过的关数
selected = [] # 保存打过的关卡
# 3. 暴力贪心:能打就打,不能打就算了(省三思路)
for a, b in levels:
if sum_a <= b: # 满足条件:当前体力 <= b
selected.append(a)
sum_a += a
count += 1
else:
# 不能直接打 → 看看能不能替换掉之前最大的a(贪心优化)
if selected and max(selected) > a:
sum_a -= max(selected)
selected.remove(max(selected))
selected.append(a)
sum_a += a
print(count)
sum_a -= max(...)→ 只做一件事:把总体力减少selected.remove(max(...))→ 只做一件事:把列表里对应的关卡删掉
