This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 2e5 + 69;
int n, l[N], r[N], q;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n;i++)
cin >> l[i] >> r[i];
cin >> q;
for (int i = 1;i <= q;i++) {
int x;
cin >> x;
vector<int> vis;
vector<int> was(n + 1);
int c = 1;
was[x] = 1;
int ans = 0;
vis.push_back(x);
while (c < n) {
int bst = 0, m = -1;
for (auto u : vis) {
int s = 0;
for (int j = l[u];j <= r[u];j++)
s += !(was[j]);
if (s > bst) {
bst = s;
m = u;
}
}
if (m == -1) {
ans = -1;
break;
}
++ans;
for (int j = l[m];j <= r[m];j++) {
if (!was[j]) {
was[j] = 1;
c++;
vis.push_back(j);
}
}
}
cout << ans << '\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |