#include <bits/stdc++.h>
using namespace std;
#define arr array
#define pii pair<int, int>
const int MX_N = 2e5 + 5;
int n;
arr<int, MX_N> vl, rq;
arr<int, MX_N> scr;
set<pii> ord;
void upd(int i, int x) {
ord.erase({scr[i], i});
scr[i] += x;
ord.insert({scr[i], i});
}
bool chck(int sz) {
for (int i = 1; i <= n; i++) scr[i] = -rq[i];
ord.clear();
for (int i = 1; i <= n; i++) ord.insert({scr[i], i});
for (int i = 1; i <= sz; i++) upd(vl[i], 1);
// cout << ord.begin()->first << " " << ord.begin()->second << endl;
if (ord.begin()->first >= 0) return true;
for (int i = sz + 1; i <= n; i++) {
upd(vl[i], 1), upd(vl[i - sz], -1);
if (ord.begin()->first >= 0) return true;
}
return false;
}
int bn_srch() {
int lw = 1, hgh = n;
while (lw != hgh) {
// cout << lw << " " << hgh << endl;
int md = (lw + hgh) / 2;
if (chck(md)) hgh = md;
else lw = md + 1;
}
return ((chck(lw)) ? lw : -1);
}
int main() {
// freopen("mrt.in", "r", stdin);
int tmp1, tmp2; cin >> n >> tmp1 >> tmp2;
for (int i = 1; i <= n; i++) { cin >> vl[i]; vl[i]++; }
for (int i = 1; i <= tmp2; i++) { int x; cin >> x; cin >> rq[x + 1]; }
int ans = bn_srch();
if (ans == -1) cout << "impossible" << endl;
else cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
680 KB |
Output is correct |
2 |
Correct |
8 ms |
600 KB |
Output is correct |
3 |
Correct |
16 ms |
604 KB |
Output is correct |
4 |
Correct |
24 ms |
600 KB |
Output is correct |
5 |
Correct |
17 ms |
604 KB |
Output is correct |
6 |
Correct |
14 ms |
672 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1381 ms |
11768 KB |
Output is correct |
2 |
Correct |
1277 ms |
11764 KB |
Output is correct |
3 |
Correct |
962 ms |
11804 KB |
Output is correct |
4 |
Correct |
1324 ms |
11792 KB |
Output is correct |
5 |
Execution timed out |
2060 ms |
12372 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2019 ms |
13444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |