#include <bits/stdc++.h>
using namespace std;
const int M=1000001,P=400001;
int m,n,b,p,x[P],y[P],u[P],v[P],c[P];
unsigned int st[M*4],sum[M*4];
vector <int> ve[M+1];
void update(int node, int l, int r, int u, int v, int val){
if (l>v||r<u)
return;
if (l>=u&&r<=v){
st[node]+=val;
sum[node]+=val;
return;
}
int mid=(l+r)>>1;
update(node<<1,l,mid,u,v,val);
update(node<<1|1,mid+1,r,u,v,val);
st[node]=min(st[node<<1],st[node<<1|1])+sum[node];
}
bool check(int sz){
for (int i=1;i<=m+1;i++)
ve[i].clear();
for (int i=1;i<=n*4;i++)
st[i]=sum[i]=0;
for (int i=1;i<=p;i++){
int X=max(x[i]-sz+1,1);
ve[X].push_back(i);
ve[u[i]+1].push_back(-i);
}
for (int i=1;i<=m-sz+1;i++){
for (int j:ve[i])
update(1,1,n-sz+1,max(y[abs(j)]-sz+1,1),v[abs(j)],c[abs(j)]*(j<0?-1:1));
if (st[1]<=b)
return true;
}
return false;
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> m >> n >> b >> p;
for (int i=1;i<=p;i++)
cin >> x[i] >> y[i] >> u[i] >> v[i] >> c[i];
int l=1,r=min(m,n),kq=0;
while (l<=r){
int mid=(l+r)>>1;
if (check(mid)){
kq=mid;
l=mid+1;
}
else
r=mid-1;
}
cout << kq;
}
Compilation message
pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:33:18: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
33 | if (st[1]<=b)
| ~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
35416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
35672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
35420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
37768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
39984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
62296 KB |
Output is correct |
2 |
Correct |
210 ms |
62624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
62544 KB |
Output is correct |
2 |
Correct |
151 ms |
62288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
37724 KB |
Output is correct |
2 |
Correct |
39 ms |
37872 KB |
Output is correct |
3 |
Correct |
35 ms |
37980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
41712 KB |
Output is correct |
2 |
Correct |
179 ms |
42072 KB |
Output is correct |
3 |
Correct |
144 ms |
42200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
66908 KB |
Output is correct |
2 |
Correct |
89 ms |
39764 KB |
Output is correct |
3 |
Correct |
135 ms |
62544 KB |
Output is correct |
4 |
Correct |
529 ms |
70768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
479 ms |
69540 KB |
Output is correct |
2 |
Correct |
843 ms |
71976 KB |
Output is correct |
3 |
Correct |
223 ms |
64336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
358 ms |
67564 KB |
Output is correct |
2 |
Correct |
1084 ms |
74580 KB |
Output is correct |
3 |
Correct |
963 ms |
74064 KB |
Output is correct |
4 |
Correct |
1075 ms |
74320 KB |
Output is correct |
5 |
Correct |
1112 ms |
74284 KB |
Output is correct |
6 |
Correct |
198 ms |
63568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4363 ms |
93100 KB |
Output is correct |
2 |
Correct |
831 ms |
64236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5033 ms |
94076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5014 ms |
94720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |