QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#251378#6693. Fast and FatTeal#WA 68ms3556kbC++141.9kb2023-11-14 17:07:232023-11-14 17:07:24

Judging History

你现在查看的是最新测评结果

  • [2023-11-14 17:07:24]
  • 评测
  • 测评结果:WA
  • 用时:68ms
  • 内存:3556kb
  • [2023-11-14 17:07:23]
  • 提交

answer

#include <set>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N (100010)
#define inf (0x3f3f3f3f)
#define INF (0x3f3f3f3f3f3f3f3fll)
#define int long long
int T, n;
struct Data {
    int v, w;
    friend bool operator< (const Data& a, const Data& b) {
        return a.w < b.w;
    }
} P[N];

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9')
        ch == '-' ? f = -1, ch = getchar() : ch = getchar();
    while (ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x * f;
}

bool cmp(const Data& a, const Data& b) {
    return a.v < b.v;
}

bool check(int x) {
    priority_queue<Data> q1, q2;
    for (int i = 1; i <= n; ++i) {
        if (P[i].v < x) q1.push(P[i]);
        else q2.push(P[i]);
    }

    if (q1.size() > q2.size()) return false;
    while (q1.size() && q2.size()) {
        Data now = q1.top();
        bool flag = false;
        while (q2.size()) {
            Data tmp = q2.top(); q2.pop();
            if (tmp.w >= now.w) {
                flag = true;
                break;
            } 
            else if (tmp.v - (now.w - tmp.w) >= x) {
                flag = true;
                break;
            }
            else continue;
        }
        if (!flag) break;
        q1.pop();
    }
    return q1.empty();
}

signed main() {
    T = read();
    while (T--) {
        n = read();
        for (int i = 1; i <= n; ++i) P[i].v = read(), P[i].w = read();
        sort(P + 1, P + n + 1, cmp);
        int l = P[1].v, r = P[n].v, mid, ans;
        while (l <= r) {
            mid = (l + r) >> 1;
            if (check(mid)) ans = mid, l = mid + 1;
            else r = mid - 1;
        }
        printf("%lld\n", ans);
    }   
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3556kb

input:

2
5
10 5
1 102
10 100
7 4
9 50
2
1 100
10 1

output:

8
1

result:

ok 2 number(s): "8 1"

Test #2:

score: -100
Wrong Answer
time: 68ms
memory: 3548kb

input:

10000
4
280251502 664541723
375808746 641141991
95134537 898607509
455259328 944978891
2
798417052 547329847
785434740 991778535
6
623628702 857611223
275667427 453747403
292209526 283132767
330752033 988721243
470297536 608192332
477186035 325224271
3
280572174 994054447
306566740 923535026
3781360...

output:

352409014
785434740
470297536
280572174
687922237
960871619
691253609
525403368
136979645
399988835
551368832
576427565
530597152
315900406
370430730
526259135
781258283
631916852
300930080
419192366
431930706
413257338
530080165
355948728
707870587
467782812
457987604
389750718
447390353
696516804
...

result:

wrong answer 5th numbers differ - expected: '704877362', found: '687922237'