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;
#include "candies.h"
#define ll long long
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
int N = c.size(), Q = v.size();
vector<int> ans(N, 0);
if(N <= 2000 && Q <= 2000){
for(int i = 0; i < Q; i++){
for(int j = l[i]; j <= r[i]; j++){
if(v[i] < 0) ans[j] = max(0, ans[j] + v[i]);
else if(v[i] > 0) ans[j] = min(c[j], ans[j] + v[i]);
}
}
}else{
vector<ll> pref(N + 1, 0);
for(int i = 0; i < Q; i++){
pref[l[i]] += v[i];
pref[r[i] + 1] -= v[i];
}
for(int i = 1; i < N; i++) pref[i] += pref[i - 1];
for(int i = 0; i < N; i++){
if(pref[i] > (ll) c[i]) ans[i] = c[i];
else ans[i] = pref[i];
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |