#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<ll>pp(n);
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=0;i<n;i++){
if(i)
pp[i]+=pp[i-1];
p[i]=max((ll)0, min((ll)pp[i], (ll)c[i]));
}
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:43:1: warning: control reaches end of non-void function [-Wreturn-type]
43 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
12 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
8804 KB |
Output is correct |
2 |
Correct |
80 ms |
12884 KB |
Output is correct |
3 |
Correct |
76 ms |
12764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
43 ms |
4940 KB |
Output isn't correct |
3 |
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 |
Incorrect |
50 ms |
4972 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 |
12 ms |
364 KB |
Output is correct |
6 |
Correct |
81 ms |
8804 KB |
Output is correct |
7 |
Correct |
80 ms |
12884 KB |
Output is correct |
8 |
Correct |
76 ms |
12764 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
43 ms |
4940 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |