# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
435871 | paisie | 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<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int ll
#define ll long long
vector<int> distribute_candies(vector <int> c, vector<int> l, vector <int>r, vector<int> v){
int n = c.size();
int q = l.size();
vector <int> pre(n+1, 0), ans(n, 0);
for(int i=0; i<q; i++){
pre[l[i]]+=v[i];
pre[r[i]+1]-=v[i];
}
ans[0] = pre[0];
for(int i=1; i<n; i++){
ans[i] = ans[i-1]+pre[i];
}
for(int i=0; i<n; i++){
ans[i] = min(ans[i], c[i]);
}
return ans;
}