#include "candies.h"
#include "bits/stdc++.h"
using namespace std;
#include <cassert>
#include <cstdio>
#include <vector>
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n = c.size();
std::vector<int> s(n);
int q = l.size();
vector<int> list[n];
for(int i=0; i<q; i++) {
for(int j=l[i]; j<=r[i]; j++) list[j].push_back(v[i]);
}
for(int i=0; i<n; i++) {
if(list[i].empty()) {
s[i] = 0; continue;
}
int k = list[i].size();
vector<pair<long long, int> > mss(k);
mss[0].first = max(0, list[i][0]);
if(list[i][0] == mss[0].first) mss[0].second = 0;
else mss[0].second = -1;
for(int j=1; j<k; j++) {
mss[j].first = max(0ll, mss[j-1].first + list[i][j]);
if(mss[j].first == 0) mss[j].second = -1;
else mss[j].second = (mss[j-1].second == -1 ? j : mss[j-1].second);
}
int optidx = 0;
for(int j=0; j<k; j++) {
if(mss[j].first >= c[i] && list[i][j] > 0) {
optidx = j + 1;
}
}
if(optidx == k) {
s[i] = c[i]; continue;
}
long long sum = 0;
long long ans = 0;
for(int j=k-1; j>=optidx; j--) {
sum += list[i][j];
if(j != optidx || optidx == 0) ans = max(ans, sum);
else ans = max(ans, sum + c[i]);
}
s[i] = ans;
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5129 ms |
1241764 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
2307 ms |
576232 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |