#include /////////////////////////// // Range Sum Query (BIT) // /////////////////////////// class RSumQBIT { private: std::vector container_; int64_t getHelper(const int index) const { if (index < 0) return 0; if ((int)(container_.size()) <= index) return container_.back(); int64_t sum{}; for (int add_place{index}; add_place > 0; add_place -= add_place & -add_place) sum += container_[add_place]; return sum; } public: RSumQBIT(const int array_size) : container_(array_size + 1) {} // indexは0-indexed void update(const int index, const int64_t added) { for (int update_place{index + 1}; update_place < (int)(container_.size()); update_place += update_place & -update_place) container_[update_place] += added; } // left,rightは0-indexed、[left, right)の半開区間 int64_t get(const int left, const int right) const { return -getHelper(left) + getHelper(right); } }; int main() { int N; scanf("%d", &N); std::vector A(N); for (auto& e: A) scanf("%lld", &e); RSumQBIT rsq(N); for (int i{}; i < N; i++) rsq.update(i, A[i]); std::vector sum(N + 1); for (int i{}; i < N; i++) sum[i + 1] = sum[i] + A[i]; int64_t max{}; for (int i{}; i + 24 <= N; i++) max = std::max(max, sum[i + 24] - sum[i]); int Q; scanf("%d", &Q); for (int loop{}; loop < Q; loop++) { int T; int64_t V; scanf("%d%lld", &T, &V); T--; rsq.update(T, V - A[T]); A[T] = V; for (int left{std::max(0, T - 23)}; left + 24 <= N; left++) max = std::max(max, rsq.get(left, left + 24)); printf("%lld\n", max); } return 0; }