不明白为什么在第 5 个点 WA 掉了
查看原帖
不明白为什么在第 5 个点 WA 掉了
112917
Eason_AC楼主2020/11/14 10:32

RT,所有的 int 全部开成了 long long 都过不去qwq

而且更玄学的是,在 51nod 的同一题上面提交在 CF 上 WA 的代码能过……

有哪位路过的大佬帮帮忙呗……实在是枯了……

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #define ll long long
    #define pq priority_queue
    #define pr pair<int, int>
    #define mp make_pair
    #define F(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
    using namespace std;
     
    inline int getint() {
    	int f = 1, x = 0; char c = getchar();
    	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
    	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
    	return x * f;
    }
    #define Rint getint()
     
    const int N = 100007;
    ll n, m, k, p, c[N], l, r, h[N], a[N];
     
    inline int check(int x) {
    	pq<pr > q;
    	F(i, 1, n) if(h[i] + m * a[i] > x) {q.push(mp(-(x / a[i]), i)); c[i] = 0;}
    	int cnt = 0;
    	for(int i = 1; !q.empty() && i <= m; ++i)
    		for(int j = 1; !q.empty() && j <= k; ++j) {
    			if(-q.top().first < i) return 0;
    			int y = q.top().second; q.pop();
    			ll w = (x + (++c[y]) * p) / a[y];
    			if(w < m) q.push(mp(-w, y));
    			++cnt;
    		}
    	F(i, 1, n) {
    		ll w = x + c[i] * p - m * a[i];
    		if (h[i] <= w) continue;
    		w = (h[i] - w - 1) / p + 1;
    		if (cnt + w > m * k) return 0;
    		cnt += w;
    	}
    	return 1;
    }
     
    int main() {
    	scanf("%lld%lld%lld%lld", &n, &m, &k, &p);
    	F(i, 1, n) scanf("%lld%lld", &h[i], &a[i]);
    	F(i, 1, n) l = max(l, a[i]), r = max(r, h[i] + m * a[i]);
    	while(l < r) {ll mid = (l + r) >> 1; if(check(mid)) r = mid; else l = mid + 1;}
    	printf("%lld", l);
    }
2020/11/14 10:32
加载中...