组队!

· · 题解

T2,好吧确实挺简单的,不知道咋紫的。

思路

先放考场思路吧,考虑拆式子变成 Ah + Bs - Ah_{min} - Bs_{min} \le C,前两个恒定,于是直接按这个排序并枚举 h_{min} 和 s_{min},但是处理不了 h \ge h_{min} 和 s \ge s_{min} 就倒闭了。

考虑换个角度拆式子,拆成 s_{min} \ge s + \frac{A(h - h_{min}) - C}{B} 直接枚举 h_{min},此时 s + \frac{A(h - h_{min}) - C}{B} \le s_{min} \le s 直接差分并枚举 s_{min} 就做完了。

时间是严格 \mathcal{O}(n^2),联考卡了 \mathcal{O}(n^2\log n)。

code

特判阴间。

#include <bits/stdc++.h>
#define pii pair<int, int>
#define st first
#define nd second
#define int long long
using namespace std;
const int N = 1e4 + 7;
int n, m, A, B, C, h[N], cnt[N], ans;
pii p[N];
signed main() {
    cin >> n >> A >> B >> C;
    for (int i = 1; i <= n; i ++)
        cin >> p[i].st >> p[i].nd, h[i] = p[i].st;
    sort(h + 1, h + n + 1);
    m = unique(h + 1, h + n + 1) - h - 1;//排序去重
    for (int i = 1; i <= m; i ++) {//钦定h[i]为最小h
        memset(cnt, 0, sizeof cnt);
        for (int j = 1; j <= n; j ++) {
            int nh = p[j].st, nv = p[j].nd;
            if (nh < h[i] || A * (nh - h[i]) > C)//第一个是好理解的,第二个考虑你的整数除法是向零取整的,在商数不到1就取整成0了
                continue;
            int l, r;//得到影响区间
            if (B == 0)//注意特判B=0,不然 RE
                l = 1;
            else
                l = max(1ll, nv - (C - A * (nh - h[i])) / B);
            r = nv;
            if (l > r)
                continue;
            cnt[l] ++, cnt[r + 1] --;
        }
        for (int j = 1; j < N; j ++)//前缀和板子
            cnt[j] += cnt[j - 1], ans = max(ans, cnt[j]);
    }
    cout << ans;
    return 0;
}