Codeforces 11.02
1.https://codeforces.com/contest/2036/problem/B
一道很简单的模拟题,直接模拟即可
代码附上:
*for _ in range(int(input())):
n,k = map(int,input().split())
a = [0]*k
while k:
x,y = map(int,input().split())
a[x-1] += y
k -= 1
print(sum(sorted(a)[-n:]))*
2.https://codeforces.com/contest/2036/problem/C
这道题目直接每改一次元素的值便查询一次是,会超时的。对一个位置i来说,它对_1100_来说影响的只有i -3 到i + 3*,附上代码:
for _ in range(int(input())):
s = input().strip(); n = len(s); S = [''] + list(s)
c = sum(1 for j in range(1, n - 2) if S[j:j + 4] == ['1', '1', '0', '0'])
for _ in range(int(input())):
i, v = map(int, input().split())
for j in range(i - 3, i + 1):
if 1 <= j <= n - 3: c -= (S[j:j + 4] == ['1', '1', '0', '0'])
S[i] = str(v)
for j in range(i - 3, i + 1):
if 1 <= j <= n - 3: c += (S[j:j + 4] == ['1', '1', '0', '0'])
print("YES" if c > 0 else "NO")