structnode { int p, k; // 第p种宝石丢在了第k个坑 booloperator<(const node &t) const { if (p == t.p) { return k > t.k; } else { return p > t.p; } } };
int n, m, q, s[N]; // n个坑,m种宝石,q个采集的宝石,s[i]表示第i种宝石的能量 vector<int> last(N, -1e6); // last[i]表示上一个第i种宝石的位置 int a[N], b[N]; // a[]为原数组,b[]为差分数组 priority_queue<node> que;
voidsolve(){ cin >> n >> m >> q; for (int i = 1; i <= m; i++) { cin >> s[i]; }
while (q--) { int p, k; cin >> p >> k; que.push({p, k}); }
while (que.size()) { auto h = que.top(); que.pop(); int p = h.p, k = h.k; // 第p种宝石丢在了第k个坑
int l, r; if (k - last[p] >= s[p]) { // 和上一种没有重叠 l = k, r = min(n, k + s[p] - 1); b[l]++, b[r + 1]--; last[p] = k; } else { // 和上一种有重叠 l = last[p] + s[p]; r = min(n, k + s[p] - 1); if (l <= r) { b[l]++, b[r + 1]--; } last[p] = k; } }
for (int i = 1; i <= n; i++) { a[i] = a[i - 1] + b[i]; cout << a[i] << " \n"[i == n]; } }
signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int T = 1; // cin >> T; while (T--) solve(); return0; }
from collections import defaultdict from typing importList, Tuple from itertools import combinations, permutations import math, heapq, queue
II = lambda: int(input()) FI = lambda: float(input()) MII = lambda: tuple(map(int, input().split())) LII = lambda: list(map(int, input().split()))
defsolve() -> None: n = II() s = [0] * (n + 1) pos, neg = 0, 0 for i inrange(1, n + 1): s[i] = II() for i inrange(2, n + 1): x = s[i] - s[i - 1] if x > 0: pos += x else: neg += x print(f"{max(pos, abs(neg))}\n{abs(pos - abs(neg)) + 1}")
if __name__ == '__main__': T = 1 # T = II() while T: solve(); T -= 1