#include "candies.h"
#include <vector>
#include <algorithm>
bool all_pos(std::vector<int> v, int n)
{
for (int i = 0; i < n; i++)
if (v[i] < 0)
return false;
return true;
}
std::vector<int> solve2(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v)
{
int i;
int n = c.size();
std::vector<int> s(n), p(n+1);
int m = v.size();
for (i = 0; i < n + 1; i++) p[i] = 0;
for (i = 0; i < m; i++) {
p[l[i]] += v[i];
p[r[i] + 1] -= v[i];
}
for (i = 1; i < n + 1; i++)
p[i] += p[i - 1];
for (i = 0; i < n; i++)
s[i] = std::min(p[i], c[i]);
return s;
}
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v)
{
int i, j;
int n = c.size();
std::vector<int> s(n);
for (i = 0; i < n; i++)
s[i] = 0;
int m = v.size();
if (all_pos(v, m)) {
s = solve2(c, l, r, v);
return s;
}
for (i = 0; i < m; i++) {
if (v[i] > 0)
for (j = l[i]; j <= r[i]; j++)
s[j] = std::min(c[j], s[j] + v[i]);
else
for (j = l[i]; j <= r[i]; j++)
s[j] = s[j] + v[i] < 0 ? 0 : s[j] + v[i];
}
return s;
}
/*
3
10 15 13
2
0 2 20
0 1 -11
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
135 ms |
11924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
229 ms |
5708 KB |
Output is correct |
3 |
Correct |
222 ms |
3816 KB |
Output is correct |
4 |
Execution timed out |
5032 ms |
8020 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
535 ms |
5716 KB |
Output is correct |
4 |
Correct |
552 ms |
2796 KB |
Output is correct |
5 |
Execution timed out |
5062 ms |
8108 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |