QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378471#6693. Fast and FatCreditTL 0ms0kbC++171.2kb2024-04-06 13:07:322024-04-06 13:07:32

Judging History

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

  • [2024-04-06 13:07:32]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-06 13:07:32]
  • 提交

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;
        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;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

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

output:


result: