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 n−1n - 1 and are initially empty. Box ii (0≤i≤n−10 \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 (0≤j≤q−10 \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 0≤l[j]≤r[j]≤n−10 \le l[j] \le r[j] \le n - 1 and v[j]≠0v[j] \ne 0. For each box kk satisfying l[j]≤k≤r[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.

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