Attempt

  • Cumulative sum can be used here.