QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378472#6693. Fast and FatCreditWA 1ms3784kbC++171.2kb2024-04-06 13:07:572024-04-06 13:07:58

Judging History

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

  • [2024-04-06 13:07:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-04-06 13:07:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
void solve()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>>a(n + 1);
    ll mx = 0;
    for (int i = 1;i <= n;i++) {
        cin >> a[i].first >> a[i].second;
        mx = max(mx, a[i].first);
    }
    int l = 1, r = mx;
    while (l <= r) {
        int mid = (r + l) >> 1;
        auto check = [&] (int x) -> bool {
            vector<ll> v1, v2;
            for (int i = 1;i <= n;i++) {
                if (a[i].first < x)v2.push_back(a[i].second);
                else v1.push_back(a[i].first + a[i].second - x);
            }
            int p1 = 0;
            sort(v1.begin(), v1.end());
            sort(v2.begin(), v2.end());
            for (auto i : v2) {
                while (p1 < v1.size() && v1[p1] < i)p1++;
                if (p1 == v1.size())return 1;
                p1++;
            }
            return 0;
        };
        if (check(mid))r = mid - 1;
        else l = mid + 1;
    }
    cout << l << endl;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3784kb

input:

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

output:

9
2

result:

wrong answer 1st numbers differ - expected: '8', found: '9'