#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxN = 1e6 + 20;
int tree[maxN << 2];
int lazy[maxN << 2];
int Lx[maxN];
int Ly[maxN];
int Rx[maxN];
int Ry[maxN];
int lx[maxN];
int ly[maxN];
int rx[maxN];
int ry[maxN];
int cost[maxN];
vector<int> queries[maxN];
int N, M, B, K;
void reset(int id, int lt, int rt) {
tree[id] = 0;
lazy[id] = 0;
if (lt == rt) {
return;
}
int mt = (lt + rt) >> 1;
reset(id << 1, lt, mt);
reset(id << 1 | 1, mt + 1, rt);
}
void update(int id, int lt, int rt, int ql, int qr, int add) {
if (lt == ql && rt == qr) {
tree[id] += add;
lazy[id] += add;
return;
}
tree[id << 1] += lazy[id];
lazy[id << 1] += lazy[id];
tree[id << 1 | 1] += lazy[id];
lazy[id << 1 | 1] += lazy[id];
lazy[id] = 0;
int mt = (lt + rt) >> 1;
if (qr <= mt) {
update(id << 1, lt, mt, ql, qr, add);
}
else if (ql >= mt + 1) {
update(id << 1 | 1, mt + 1, rt, ql, qr, add);
}
else {
update(id << 1, lt, mt, ql, mt, add);
update(id << 1 | 1, mt + 1, rt, mt + 1, qr, add);
}
tree[id] = min(tree[id << 1], tree[id << 1 | 1]);
}
bool check(int sz) {
int n = N - sz + 1;
int m = M - sz + 1;
for (int i = 1; i <= n; i++) {
queries[i].clear();
}
for (int i = 1; i <= K; i++) {
lx[i] = max(1, Lx[i] - sz + 1);
rx[i] = min(n, Rx[i]);
ly[i] = max(1, Ly[i] - sz + 1);
ry[i] = min(m, Ry[i]);
if (lx[i] <= rx[i] && ly[i] <= ry[i]) {
queries[lx[i]].push_back(i);
if (rx[i] < n) {
queries[rx[i] + 1].push_back(-i);
}
}
}
reset(1, 1, m);
for (int i = 1; i <= n; i++) {
for (auto id: queries[i]) {
if (id > 0) {
update(1, 1, m, ly[id], ry[id], cost[id]);
}
else {
update(1, 1, m, ly[-id], ry[-id], -cost[-id]);
}
}
if (tree[1] <= B) {
return true;
}
}
return false;
}
void just_do_it() {
cin >> N >> M >> B >> K;
for (int i = 1; i <= K; i++) {
cin >> Lx[i] >> Ly[i] >> Rx[i] >> Ry[i] >> cost[i];
}
int res = 0;
int lt = 1;
int rt = min(N, M);
while (lt <= rt) {
int mt = (lt + rt) >> 1;
if (check(mt)) {
res = mt;
lt = mt + 1;
}
else {
rt = mt - 1;
}
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
26244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
32352 KB |
Output is correct |
2 |
Correct |
246 ms |
40780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
40804 KB |
Output is correct |
2 |
Correct |
84 ms |
32184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
24276 KB |
Output is correct |
2 |
Correct |
61 ms |
24520 KB |
Output is correct |
3 |
Correct |
48 ms |
24532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
28492 KB |
Output is correct |
2 |
Correct |
261 ms |
29040 KB |
Output is correct |
3 |
Correct |
211 ms |
29208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
37152 KB |
Output is correct |
2 |
Correct |
83 ms |
29036 KB |
Output is correct |
3 |
Correct |
137 ms |
41232 KB |
Output is correct |
4 |
Correct |
544 ms |
49344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
48304 KB |
Output is correct |
2 |
Correct |
938 ms |
50992 KB |
Output is correct |
3 |
Correct |
114 ms |
34636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
37956 KB |
Output is correct |
2 |
Correct |
1166 ms |
53632 KB |
Output is correct |
3 |
Correct |
1056 ms |
53296 KB |
Output is correct |
4 |
Correct |
1154 ms |
53372 KB |
Output is correct |
5 |
Correct |
1111 ms |
53556 KB |
Output is correct |
6 |
Correct |
66 ms |
33844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5056 ms |
78008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5059 ms |
81892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5038 ms |
84140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |