PivotOJ

Distributing Candies

시간 제한: 4000ms메모리 제한: 2048MB출처: IOI 2021BOJ 22023

문제

Aunty Khong is preparing nn boxes of candies for students from a nearby school. The boxes are numbered from 00 to n1n - 1 and are initially empty. Box ii (0in10 \le i \le n - 1) has a capacity of c[i]c[i] candies.

Aunty Khong spends qq days preparing the boxes. On day jj (0jq10 \le j \le q - 1), she performs an action specified by three integers l[j]l[j], r[j]r[j] and v[j]v[j] where 0l[j]r[j]n10 \le l[j] \le r[j] \le n - 1 and v[j]0v[j] \ne 0. For each box kk satisfying l[j]kr[j]l[j] \le k \le r[j]:

  • If v[j]>0v[j] > 0, Aunty Khong adds candies to box kk, one by one, until she has added exactly v[j]v[j] candies or the box becomes full. In other words, if the box had pp candies before the action, it will have min(c[k],p+v[j])\min{(c[k], p + v[j])} candies after the action.
  • If v[j]<0v[j] < 0, Aunty Khong removes candies from box kk, one by one, until she has removed exactly v[j]-v[j] candies or the box becomes empty. In other words, if the box had pp candies before the action, it will have max(0,p+v[j])\max{(0, p + v[j])} candies after the action.

Your task is to determine the number of candies in each box after the qq days.

코드를 제출하려면 로그인하세요.