#include "candies.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
vector<int> s(n,0);
int q=l.size();
bool yes=true;
for(int i = 0 ; i < q ; i++){
if(v[i]<0){
yes=false;break;
}
}
if(!yes){
for(int i = 0 ; i < q ; i++){
for(int j = l[i] ; j <= r[i] ; j ++){
if(v[i] > 0) s[j] = min(c[j],s[j]+v[i]);
else s[j] = max(0,s[j]+v[i]);
}
}
return s;
}
vector<int> not_F;
for(int i = 0 ;i < n ; i++) not_F.push_back(i);
for(int i = 0 ; i < q ; i++){
int li=0,ri=not_F.size()-1,mid1=l[i],mid2=r[i];
while(li <= ri){
mid1=(ri+li)/2;
if(not_F[mid1] >= l[i]){
ri= mid1-1;
}
else{
li=mid1+1;
}
}
li=0,ri=not_F.size()-1;
while(li <= ri){
mid2=(ri+li)/2;
if(not_F[mid2] <= r[i]){
li= mid2+1;
}
else{
ri=mid2-1;
}
}
for(int j = mid1;j<=mid2;j++){
s[j] = min(c[j],s[j]+v[i]);
if(s[j]==c[j]) not_F.erase(not_F.begin()+j);
}
}
return s;
}
/*vector<int> distribute_candies1(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
vector<int> s(n,0);
int q=l.size();
for(int i = 0 ; i < q ; i++){
for(int j = l[i] ; j <= r[i] ; j ++){
if(v[i] > 0) s[j] = min(c[j],s[j]+v[i]);
else s[j] = max(0,s[j]+v[i]);
}
}
return s;
}
int main(){
int n,q;
cin >> n >> q;
vector<int>c(n),l(q),r(q),v(q);
for(int i = 0 ; i < n ; i++) cin >> c[i];
for(int i = 0 ; i < q ; i++) cin >> l[i];
for(int i = 0 ; i < q ; i++) cin >> r[i];
for(int i = 0 ; i < q ; i++) cin >> v[i];
vector<int> cc = distribute_candies2(c,l,r,v);
cout <<"daz"<<endl;
for(int c:cc)cout<<c<<" ";
cout << endl;
vector<int> cc2 = distribute_candies1(c,l,r,v);
for(int c:cc2)cout<<c<<" ";
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1038 ms |
17056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
210 ms |
5100 KB |
Output is correct |
3 |
Correct |
170 ms |
3908 KB |
Output is correct |
4 |
Execution timed out |
5085 ms |
7476 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
432 ms |
5160 KB |
Output is correct |
4 |
Correct |
409 ms |
2844 KB |
Output is correct |
5 |
Execution timed out |
5053 ms |
7348 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |