#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, t = 0, ch;
  while (!isdigit(ch = getchar())) t = ch == '-';
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return t ? -x : x;
}
template <typename T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
const int MAXN = 100000;
struct Val {
  int v, l, r;
  friend bool operator<(Val a, Val b) { return a.v < b.v; }
  friend bool operator<=(Val a, Val b) { return a.v <= b.v; }
  friend bool operator>(Val a, Val b) { return a.v > b.v; }
  friend bool operator>=(Val a, Val b) { return a.v >= b.v; }
  friend Val operator+(Val a, Val b) {
    return (Val){a.v + b.v, Min(a.l, b.l), Max(a.r, b.r)};
  }
};
struct Node {
  Val t;
  int tag;
  Val la, ra, fa;
  Val lb, rb, fb;
  Node(int t = 0) { tag = 0; }
};
inline void rev(int);
inline Node Merge(Node, Node);
inline void pushdown(int, int);
inline void pushup(Node&, Node, Node);
inline void build(int, int, int);
inline void modify(int, int, int, int, int);
inline void reverse(int, int, int, int, int);
inline Node Query(int, int, int, int, int);
inline void debug(int, int, int);
Node T[MAXN << 2];
Node sta[100];
int cnt;
int main() {
  int n = read();
  build(1, 1, n);
  int m = read();
  while (m--) {
    int opt = read();
    if (opt) {
      int l = read(), r = read(), k = read(), res = 0;
      cnt = 0;
      while (k--) {
        Node tmp = Query(1, 1, n, l, r);
        if (tmp.fa.v <= 0) break;
        res += tmp.fa.v;
        reverse(1, 1, n, tmp.fa.l, tmp.fa.r);
        sta[cnt++] = tmp;
      }
      while (cnt) --cnt, reverse(1, 1, n, sta[cnt].fa.l, sta[cnt].fa.r);
      printf("%d\n", res);
    } else {
      int pos = read(), x = read();
      modify(1, 1, n, pos, x);
    }
  }
  return 0;
}
inline void rev(int nd) {
  swap(T[nd].la, T[nd].lb);
  swap(T[nd].ra, T[nd].rb);
  swap(T[nd].fa, T[nd].fb);
  T[nd].t.v *= -1;
  T[nd].la.v *= -1;
  T[nd].lb.v *= -1;
  T[nd].ra.v *= -1;
  T[nd].rb.v *= -1;
  T[nd].fa.v *= -1;
  T[nd].fb.v *= -1;
  T[nd].tag ^= 1;
}
inline void pushdown(int nd) {
  if (T[nd].tag) T[nd].tag = 0, rev((nd << 1)), rev((nd << 1 | 1));
}
inline void pushup(Node& nd, Node l, Node r) {
  nd.t = l.t + r.t;
  nd.la = Max(l.la, l.t + r.la);
  nd.ra = Max(r.ra, r.t + l.ra);
  nd.fa = Max(Max(l.fa, r.fa), l.ra + r.la);
  nd.lb = Min(l.lb, l.t + r.lb);
  nd.rb = Min(r.rb, r.t + l.rb);
  nd.fb = Min(Min(l.fb, r.fb), l.rb + r.lb);
}
inline Node Merge(Node l, Node r) {
  Node nd;
  pushup(nd, l, r);
  return nd;
}
inline void build(int nd, int l, int r) {
  if (l == r) {
    T[nd].t.l = T[nd].t.r = l, T[nd].t.v = read();
    T[nd].la = T[nd].ra = T[nd].fa = T[nd].lb = T[nd].rb = T[nd].fb = T[nd].t;
    return;
  }
  int mid = (l + r) >> 1;
  build((nd << 1), l, mid), build((nd << 1 | 1), mid + 1, r);
  pushup(T[nd], T[(nd << 1)], T[(nd << 1 | 1)]);
}
inline void modify(int nd, int l, int r, int p, int v) {
  if (l == r) {
    T[nd].t.v = v;
    T[nd].la = T[nd].ra = T[nd].fa = T[nd].lb = T[nd].rb = T[nd].fb = T[nd].t;
    return;
  }
  pushdown(nd);
  int mid = (l + r) >> 1;
  if (p <= mid)
    modify((nd << 1), l, mid, p, v);
  else
    modify((nd << 1 | 1), mid + 1, r, p, v);
  pushup(T[nd], T[(nd << 1)], T[(nd << 1 | 1)]);
}
inline void reverse(int nd, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    rev(nd);
    return;
  }
  pushdown(nd);
  int mid = (l + r) >> 1;
  if (L <= mid) reverse((nd << 1), l, mid, L, R);
  if (mid < R) reverse((nd << 1 | 1), mid + 1, r, L, R);
  pushup(T[nd], T[(nd << 1)], T[(nd << 1 | 1)]);
}
inline Node Query(int nd, int l, int r, int L, int R) {
  if (L == l && r == R) return T[nd];
  pushdown(nd);
  int mid = (l + r) >> 1;
  if (R <= mid) return Query((nd << 1), l, mid, L, R);
  if (mid < L) return Query((nd << 1 | 1), mid + 1, r, L, R);
  return Merge(Query((nd << 1), l, mid, L, mid),
               Query((nd << 1 | 1), mid + 1, r, mid + 1, R));
}
inline void print(Node x) {
  printf("fa: %d %d %d; %d %d\n", x.fa.l, x.fa.r, x.fa.v, x.t.l, x.t.r);
}
inline void debug(int nd, int l, int r) {
  if (l == r) return print(T[nd]);
  pushdown(nd);
  int mid = (l + r) >> 1;
  debug((nd << 1), l, mid), debug((nd << 1 | 1), mid + 1, r);
  print(T[nd]);
}
