You are given an array a consisting n(1=<n<=10^6) integers a1,a2,…,an(-10^9<=ai<=10^9 for each 1<=i<=n) and an integer k(1<=k<=n). You can do any number of operations.In each option you can choose an interval [l,r] with a length of k and multiply the number al,al+1,…ar in array a by -1.You have to output the maximum value of the sum of the array a after any number of options.
You need to answer 100 independent questions.Each question has a time limit of 5 seconds.
from typing importList from math import inf from pwn import *
defsolve_half(arr: List[int], k: int) -> int: n = len(arr) group_na_cnt = [0] * k # 每组负数个数 group_sum = [0] * k # 每组的绝对值和 group_min = [inf] * k # 每组最小的数 for i inrange(n): x = i % k if arr[i] < 0: group_na_cnt[x] += 1 group_sum[x] += abs(arr[i]) group_min[x] = min(group_min[x], abs(arr[i])) ans = 0 for j inrange(k): if group_na_cnt[j] % 2 == 0: ans += group_sum[j] else: ans += group_sum[j] - 2 * group_min[j] return ans
context.log_level='info' p = remote('172.52.x.x', 9999)
z = 100 for i inrange(z): p.recvuntil('Challenge Input:\n') nk = p.recvline(keepends=False).decode() arrstr = p.recvline(keepends=False).decode() k = int(nk.split(' ')[1]) arr = [int(x) for x in arrstr.split(' ')] res = str(solve(arr, k)) p.recvuntil('Give me your output:\n') p.sendline(res.encode()) print("#" + str(i))
context.log_level='debug' flag = True while flag: p = remote('172.52.x.x', 9999) p.recvuntil(b'>') p.sendline(b'Y') left = 100000 right = 999999 whileTrue: p.recvuntil(b'Please enter a number:') mid = (left + right) // 2 p.sendline(str(mid)) r = p.recvline(keepends=False).decode() if r.strip() == 'low': left = mid elif r.strip() == 'up': right = mid else: print(r) if r != 'You lost': flag = False break p.close()
defgetShaAns(e: str, target: str) -> str: tables = string.ascii_letters + string.digits for i in tables: for j in tables: for k in tables: for l in tables: s = i + j + k + l + e if hashlib.sha256(s.encode()).hexdigest() == target: return s return""
ans = getShaAns(ends, shares) p.recvuntil('Give me XXXX:\n') p.sendline(ans[:4]) number = "0" last = "0" try: whileTrue: a = p.recvuntil("Please your guess : ").decode() if'flag'in a: print(a) flag = False break if'Fail'in a: searchObj = re.search( r'Fail! The number is ([0-9]+)', a, re.M|re.I) if searchObj: now = searchObj.group(1) if now == last: number = now last = now p.sendline(number) except EOFError: pass