#include<bits/stdc++.h>
#include "candies.h"
using namespace std;
#define ll long long
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n=c.size(), q=l.size();
vector<int>p(n);
bool all_pos=1;
for(int j=0;j<q;j++){
if(v[j]<0)
all_pos=0;
}
if((ll)n*q<=1e8){
for(int i=0;i<n;i++){
for(int j=0;j<q;j++){
if(i>=l[j] && i<=r[j]){
p[i]=min(c[i], max(0, p[i]+v[j]));
}
}
}
return p;
}
if(all_pos){
vector<int>pp=p;
for(int j=0;j<q;j++){
pp[l[j]]+=v[j];
if(r[j]!=n-1)
pp[r[j]+1]-=v[j];
}
for(int i=1;i<n;i++){
pp[i]+=pp[i-1];
p[i]=min((ll)pp[i], (ll)0);
}
return p;
}
}
//int main() {
// int n;
// assert(1 == scanf("%d", &n));
// std::vector<int> c(n);
// for(int i = 0; i < n; ++i) {
// assert(scanf("%d", &c[i]) == 1);
// }
//
// int q;
// assert(1 == scanf("%d", &q));
// std::vector<int> l(q), r(q), v(q);
// for(int i = 0; i < q; ++i) {
// assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
// }
//
// std::vector<int> ans = distribute_candies(c, l, r, v);
//
// for(int i = 0; i < n; ++i) {
// if (i > 0) {
// printf(" ");
// }
// printf("%d", ans[i]);
// }
// printf("\n");
// fclose(stdout);
// return 0;
//}
Compilation message
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
42 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
11 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
8040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
39 ms |
5392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
48 ms |
5408 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
11 ms |
340 KB |
Output is correct |
6 |
Incorrect |
79 ms |
8040 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |