#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=2e5+99;
int n,q,c[N],a[N];
ll b[N];
vector<int> s,t,val,ad[N],dl[N];
vector<int> distribute_candies(vector<int> _c,vector<int> _s,vector<int> _t,vector<int> _val){
s=_s,t=_t,val=_val;
n=_c.size(),q=s.size();
vector<int> ans(n);
f(i,0,n) c[i]=_c[i];
f(i,0,q){
ad[s[i]].pb(i);
dl[t[i]].pb(i);
}
f(i,0,n){
for(auto x : ad[i]) a[x+1]+=val[x];
int mnid=q,mxid=q,b0=q,b1=q;
ll sum=0;
f(j,1,q+1){
b[j]=b[j-1]+a[j];
sum+=a[j];
maxm(sum,0ll);
minm(sum,1ll*c[i]);
}
f_(j,q,0){
if(b[j]<b[mnid]){
mnid=j;
if(b[mxid]-b[j]<c[i]){
b0=j;
}
}
if(b[j]>b[mxid]){
mxid=j;
if(b[j]-b[mnid]<c[i]){
b1=j;
}
}
}
//dbga(b,0,q+1);
//cout<<b0<<" "<<b1<<endl;
ans[i]=sum;
for(auto x : dl[i]) a[x+1]-=val[x];
}
return ans;
}
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:41:27: warning: variable 'b0' set but not used [-Wunused-but-set-variable]
41 | int mnid=q,mxid=q,b0=q,b1=q;
| ^~
candies.cpp:41:32: warning: variable 'b1' set but not used [-Wunused-but-set-variable]
41 | int mnid=q,mxid=q,b0=q,b1=q;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9712 KB |
Output is correct |
3 |
Correct |
5 ms |
9848 KB |
Output is correct |
4 |
Correct |
7 ms |
9848 KB |
Output is correct |
5 |
Correct |
17 ms |
9940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5060 ms |
31008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
1163 ms |
23508 KB |
Output is correct |
3 |
Correct |
1119 ms |
16392 KB |
Output is correct |
4 |
Execution timed out |
5042 ms |
35332 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
1135 ms |
20856 KB |
Output is correct |
4 |
Correct |
1111 ms |
13080 KB |
Output is correct |
5 |
Execution timed out |
5066 ms |
23916 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9712 KB |
Output is correct |
3 |
Correct |
5 ms |
9848 KB |
Output is correct |
4 |
Correct |
7 ms |
9848 KB |
Output is correct |
5 |
Correct |
17 ms |
9940 KB |
Output is correct |
6 |
Execution timed out |
5060 ms |
31008 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |