#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;
// vi distribute_candies(vi c, vi l, vi r, vi v) {
// int n = c.size();
// int q = l.size();
// vi res(n);
// for (int i = 0; i < q; i++) {
// for (int j = l[i]; j <= r[i]; j++) {
// res[j] += v[i];
// if (res[j] > c[j]) res[j] = c[j];
// if (res[j] < 0) res[j] = 0;
// }
// }
// return res;
// }
void p(vi a) {
for (int i : a) cout << i << ' ';
cout << endl;
}
vi distribute_candies(vi c, vi l, vi r, vi v) {
int n = c.size();
int q = l.size();
vi diff(n, 0);
for (int i = 0; i < q; i++) {
diff[l[i]] = v[i];
diff[r[i] + 1] = -v[i];
}
vi res(n);
res[0] = diff[0];
for (int i = 1; i < n; i++) {
res[i] = res[i - 1] + diff[i];
}
for (int i = 0; i < n; i++) {
res[i] = min(res[i], c[i]);
}
return res;
}
int main() {
p(distribute_candies(
{10, 10, 10, 10},
{0, 1, 2},
{3, 3, 3},
{4, 4, 4}
));
}
Compilation message
/usr/bin/ld: /tmp/ccvMfH6V.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccmLkSKV.o:candies.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status