import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  implicit val box = readLine.trim.split(' ').map(it ⇒ new Box(it.toInt))
  println(
    readOrder(readLine.trim.toInt)
  )
  class Box(val capacity: Int, var using: Int = 0) {
    def restSpace: Int = capacity - using
  }
  @tailrec def readOrder(orderLimit: Int)(implicit box: Array[Box]): Int = {
    if (orderLimit == 0) 0
    else {
      val Array(t, x, d) = readLine.trim.split(' ').map(_.toInt)
      t match{
        case 1 if box(x - 1).restSpace >= d ⇒ {
          box(x - 1).using += d
          readOrder(orderLimit - 1)
        }
        case 2 if box(x - 1).using >= d ⇒ {
          box(x - 1).using -= d
          readOrder(orderLimit - 1)
        }
        case _ ⇒ x
      }
    }
  }
}
