structNode { int l, r, d; }node[N]; int a[N]; int n, m, k, t; map<int, int> mp;
boolcheck(int x, int y){ int T = 0; mp.clear(); for (int i = 1; i <= k; i++) { if (node[i].d > y) { // 如果该段危险值大于下限,加上这段 mp[node[i].l]++; mp[node[i].r+1]--; } } int pre = 0; // 前缀和 for (int i = 1; i <= n+1; i++) { pre += mp[i]; if (pre >= 1) { // 如果当前位置大于等于1,说明要先摧毁陷阱,故在这个点上花费的时间为3 T += 3; } else { T++; } } return T <= t; }
intmain(){
cin >> m >> n >> k >> t; for (int i = 1; i <= m; i++) cin >> a[i]; for (int i = 1; i <= k; i++) { cin >> node[i].l >> node[i].r >> node[i].d; } sort(a+1, a+1+m, greater<int>()); int l = 0, r = m, mid; while (l < r) { mid = (l+r+1) >> 1; // 这里要注意向上取整,即相邻的数优先判断大的是否满足条件 if (check(mid, a[mid])) { l = mid; } else { r = mid - 1; }