# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544056 | brunnorezendes | Distributing Candies (IOI21_candies) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "candies.h"
#include <bits/stdc++.h>
#define s second
#define f first
#define max 10e9 + 1
using namespace std;
typedef vector <int> vi;
typedef pair<pair<int,int> , int> iii;
typedef vector<iii> viii;
vi distribute_candies(vi c, vi l, vi r, vi v){
int q = l.size(), n = c.size(), i, flag=0, type, ind, sum=0, aux;
vi val(n, 0);
viii sweep;
for(i=0;i<q;i++){
if(v[i]<0) flag=1;
sweep.push_back({{l[i], 0}, i});
sweep.push_back({{r[i], 2}, i});
}
for(i=0;i<n;i++){
sweep.push_back({{i, 1}, i});
}
sort(sweep.begin(), sweep.end());
for(i=0;i<sweep.size();i++){
ind = sweep[i].s;
type = sweep[i].f.s;
if(type == 1){
val[ind] = min(c[ind], sum);
}
else if(flag){
if(type == 2) sum-=v[ind];
else sum+=v[ind];
aux = sum;
sum = max(0, sum);
sum = min(c[0], sum);
v[ind] += sum-aux;
}
else{
if(type == 2) sum-=v[ind];
else sum+=v[ind];
}
sum %= max;
}
return val;
}