#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];
long long st[M*4],lazy[M*4];
vector <int> ve[M+1];
void down(int node, int l, int r){
if (!lazy[node]||l==r)
return;
st[node<<1]+=lazy[node];
st[node<<1|1]+=lazy[node];
lazy[node<<1]+=lazy[node];
lazy[node<<1|1]+=lazy[node];
lazy[node]=0;
}
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;
lazy[node]+=val;
return;
}
down(node,l,r);
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]);
}
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]=lazy[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
35420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
35420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
35416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
35532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
42076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
93480 KB |
Output is correct |
2 |
Correct |
289 ms |
93428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
93488 KB |
Output is correct |
2 |
Correct |
216 ms |
93268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35680 KB |
Output is correct |
2 |
Correct |
44 ms |
35940 KB |
Output is correct |
3 |
Correct |
38 ms |
35920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
44028 KB |
Output is correct |
2 |
Correct |
220 ms |
44624 KB |
Output is correct |
3 |
Correct |
184 ms |
44648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
410 ms |
98020 KB |
Output is correct |
2 |
Correct |
77 ms |
40272 KB |
Output is correct |
3 |
Correct |
183 ms |
93520 KB |
Output is correct |
4 |
Correct |
642 ms |
101712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
609 ms |
100812 KB |
Output is correct |
2 |
Correct |
1065 ms |
103156 KB |
Output is correct |
3 |
Correct |
301 ms |
95748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
463 ms |
98960 KB |
Output is correct |
2 |
Correct |
1346 ms |
105904 KB |
Output is correct |
3 |
Correct |
1260 ms |
105764 KB |
Output is correct |
4 |
Correct |
1380 ms |
105676 KB |
Output is correct |
5 |
Correct |
1385 ms |
105824 KB |
Output is correct |
6 |
Correct |
274 ms |
95320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5024 ms |
127096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5043 ms |
129340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5054 ms |
130308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |