#include <bits/stdc++.h>
using namespace std;
int n;
struct Segment {
  int val, st, ed;
  Segment(const int _val = 0, const int _st = 0, const int _ed = 0) {
    val = _val;
    st = _st;
    ed = _ed;
  }
};
bool operator<(const Segment a, const Segment b) { return a.val < b.val; }
Segment operator+(const Segment a, const Segment b) {
  return Segment(a.val + b.val, a.st, b.ed);
}
struct Data {
  int flag;
  Segment sum, le, ri, best;
  Data(const int pos = 0, const int val = 0, const int flag = 0) : flag(flag) {
    sum = Segment(val, pos, pos);
    if ((val >= 0) ^ flag) {
      le = ri = best = sum;
    } else {
      le = Segment(0, pos, pos - 1);
      ri = Segment(0, pos + 1, pos);
      best = Segment(0, pos, pos - 1);
    }
  }
  void reverse() {
    flag ^= 1;
    sum.val = -sum.val;
    le.val = -le.val;
    ri.val = -ri.val;
    best.val = -best.val;
  }
};
Data merge(const Data a, const Data b) {
  Data ret;
  ret.flag = a.flag;
  ret.sum = a.sum + b.sum;
  if (!ret.flag) {
    ret.le = max(a.le, a.sum + b.le);
    ret.ri = max(b.ri, a.ri + b.sum);
    ret.best = max(a.ri + b.le, max(a.best, b.best));
  } else {
    ret.le = min(a.le, a.sum + b.le);
    ret.ri = min(b.ri, a.ri + b.sum);
    ret.best = min(a.ri + b.le, min(a.best, b.best));
  }
  return ret;
}
const int N = 100010;
Data data[3 * N][2];
void update(int u) {
  int ls = 2 * u, rs = 2 * u + 1;
  data[u][0] = merge(data[ls][0], data[rs][0]);
  data[u][1] = merge(data[ls][1], data[rs][1]);
  return;
}
void Push_down(int u, int L, int R);
void segChange(int u, int L, int R, int pos, int val) {
  if (pos < L || pos > R) return;
  if (L == R) {
    data[u][0] = Data(L, val, 0);
    data[u][1] = Data(L, val, 1);
  } else {
    int ls = 2 * u, rs = 2 * u + 1;
    int mid = (L + R) >> 1;
    segChange(ls, L, mid, pos, val);
    segChange(rs, mid + 1, R, pos, val);
    update(u);
  }
  return;
}
int flag[3 * N];
void segReverse(int u, int L, int R, int a, int b);
void Push_down(int u, int L, int R) {
  if (flag[u]) {
    int mid = (L + R) >> 1;
    int ls = 2 * u, rs = 2 * u + 1;
    flag[u] ^= 1;
    segReverse(ls, L, mid, L, R);
    segReverse(rs, mid + 1, R, L, R);
  }
  return;
}
void segReverse(int u, int L, int R, int a, int b) {
  if (b < L || R < a) return;
  if (a <= L && R <= b) {
    flag[u] ^= 1;
    swap(data[u][0], data[u][1]);
    data[u][0].reverse();
    data[u][1].reverse();
    return;
  }
  Push_down(u, L, R);
  int mid = (L + R) >> 1;
  int ls = 2 * u, rs = 2 * u + 1;
  segReverse(ls, L, mid, a, b);
  segReverse(rs, mid + 1, R, a, b);
  update(u);
  return;
}
Data segAsk(int u, int L, int R, int a, int b) {
  if (a <= L && R <= b) return data[u][0];
  int mid = (L + R) >> 1;
  int ls = 2 * u, rs = 2 * u + 1;
  Push_down(u, L, R);
  if (b <= mid) return segAsk(ls, L, mid, a, b);
  if (mid < a) return segAsk(rs, mid + 1, R, a, b);
  return merge(segAsk(ls, L, mid, a, b), segAsk(rs, mid + 1, R, a, b));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int t1;
    scanf("%d", &t1);
    segChange(1, 0, n - 1, i, t1);
  }
  int m;
  scanf("%d", &m);
  while (m--) {
    int tp;
    scanf("%d", &tp);
    if (tp) {
      int l, r, k;
      scanf("%d%d%d", &l, &r, &k);
      l--;
      r--;
      int ans = 0;
      vector<pair<int, int> > v;
      for (int i = 0; i < k; i++) {
        Segment tmp = segAsk(1, 0, n - 1, l, r).best;
        if (tmp.val > 0) {
          ans += tmp.val;
          segReverse(1, 0, n - 1, tmp.st, tmp.ed);
          v.push_back(make_pair(tmp.st, tmp.ed));
        }
      }
      printf("%d\n", ans);
      for (int i = 0; i < (int)v.size(); i++) {
        segReverse(1, 0, n - 1, v[i].first, v[i].second);
      }
    } else {
      int tpos, tval;
      scanf("%d%d", &tpos, &tval);
      tpos--;
      segChange(1, 0, n - 1, tpos, tval);
    }
  }
  return 0;
}
