QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666588#6693. Fast and FatTJUHuangTaoWA 64ms3592kbC++201.4kb2024-10-22 19:13:052024-10-22 19:13:07

Judging History

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

  • [2024-10-22 19:13:07]
  • 评测
  • 测评结果:WA
  • 用时:64ms
  • 内存:3592kb
  • [2024-10-22 19:13:05]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define ll long long
#define pii pair<int, int>
#define tii tuple<int, int, int>
#define db double
#define all(a) a.begin(), a.end()
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 998244353;
pii arr[maxn];
int n;
bool ck(int mid) {
    vector<int> vec1, vec2;
    for (int i = 1; i <= n; i++) {
        auto [v, w] = arr[i];
        if (mid < v) {
            vec1.push_back(w + (v - mid));
        } 
        else if (mid > v) 
            vec2.push_back(w);
    }
    sort(all(vec1)), sort(all(vec2));
    if (vec2.size() > vec1.size()) return 0;
    reverse(all(vec1)), reverse(all(vec2));
    for (int i = 0; i < vec2.size(); i++)
        if (vec1[i] < vec2[i]) return 0;
    return 1;
}
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int v, w; cin >> v >> w;
        arr[i] = {v, w};
    }
    sort(arr + 1, arr + 1 + n);
    int l = 1, r = 1e9, ans = 1;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (ck(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    cout << ans << "\n";
}
signed main() {
    // freopen("1.in", "r", stdin);
    // freopen("1.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 64ms
memory: 3552kb

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
470297535
280572173
704877362
960871618
691253608
560579094
136979645
399988835
610497257
576427564
636500913
315900405
370430730
526259135
781258283
631916851
300930080
419999539
431930706
479323438
530080164
391912906
708925498
467782812
457987604
389750718
447390353
696516804
...

result:

wrong answer 3rd numbers differ - expected: '470297536', found: '470297535'