# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1253446 | lumine88 | Jousting tournament (IOI12_tournament) | C++17 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
/// tournament tree
vector<int> tree[N];
int leaf, rnk[N], idx[N];
int n, m, late;
int dfs(int u) {
if (u == 0) {
leaf++;
return -1;
}
int start = leaf, res = -1;
for (int v : tree[u]) {
res = max(res, dfs(v));
if (v != tree[u].back())
res = max(res, rnk[leaf]);
}
if (res < late) {
idx[start]++;
idx[leaf]--;
}
return res;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> late;
for (int i = 1; i < n; i++)
cin >> rnk[i];
for (int i = 1; i <= m; i++) {
int l, r;
cin >> l >> r;
for (int j = l; j <= r; j++) {
tree[i].push_back(idx[j]);
idx[j] = 0;
}
idx[l] = i;
}
memset(idx, 0, sizeof idx);
dfs(m);
leaf = 0;
for (int i = 0; i < n; i++) {
idx[i + 1] += idx[i];
if (idx[leaf] < idx[i])
leaf = i;
}
cout << leaf;
}