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>
using namespace std;
#define ll long long
#define pb push_back
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size(), q = l.size();
if (n <= 2000 && q <= 2000) {
vector<int> a(n, 0);
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
a[j] += v[i];
a[j] = min(a[j], c[j]);
a[j] = max(a[j], 0);
}
}
return a;
}
bool allpos = true;
for (int &x : v) {
allpos &= (x > 0);
}
if (allpos) {
ll int diff[n] = {0};
for (int i = 0; i < q; i++) {
diff[l[i]] += v[i];
if (r[i] != n - 1) diff[r[i] + 1] -= v[i];
}
vector<int> ans;
ll int ps = 0;
for (int i = 0; i < n; i++) {
ps += diff[i];
ans.pb((ps < c[i] ? ps : c[i]));
}
return ans;
}
return {};
}
# | 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... |