using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int Q = int.Parse(Console.ReadLine()); int[] T = new int[N]; int[] V = new int[N]; for (int i = 0; i < Q; i++) { string s = Console.ReadLine(); T[i] = int.Parse(s.Split(' ')[0]); V[i] = int.Parse(s.Split(' ')[1]); } int sum = 0; for (int i = 0; i < 24; i++) { sum += A[i]; } //最大値(逐次変わる) int max = sum; //まずは変更なしの状態での、連続最大値を求める for (int i = 0; i < N - 24; i++) { max = Math.Max(max, max - A[i] + A[i + 24]); } //変更後の最大値を求める for (int i = 0; i < Q; i++) { //変化を起こす A[T[i] - 1] = V[i]; int after_max = 0; //変化点が、中央に収まっているとき if (T[i] >= 24 && T[i] <= N - 23) { //左端から24個カウントした和を取る for (int j = T[i] - 24; j <= T[i] - 1; j++) { after_max += A[j]; } for (int j = T[i] - 24; j <= T[i] - 2; j++) { after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]); } //変化点の右端が、詰まっているとき } else if (T[i] >= 24) { //左端から24個カウントした和を取る for (int j = T[i] - 24; j <= T[i] - 1; j++) { after_max += A[j]; } for (int j = T[i] - 24; j <= N - 25; j++) { after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]); } //変化点の左端が、詰まっているとき } else if (T[i] <= N - 23) { for (int j = 0; j < 24; j++) { after_max += A[j]; } for (int j = 0; j <= T[i] - 2; j++) { after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]); } //変化点の両端が詰まっているとき } else { for (int j = 0; j < 24; j++) { after_max += A[j]; } for (int j = 0; j <= N - 25; j++) { after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]); } } //Console.WriteLine(after_max); max = Math.Max(max, after_max); //出力 Console.WriteLine(max); } } }