QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268057#6693. Fast and FatliangqianxingRE 0ms3780kbC++233.4kb2023-11-28 00:53:502023-11-28 00:53:50

Judging History

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

  • [2023-11-28 00:53:50]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3780kb
  • [2023-11-28 00:53:50]
  • 提交

answer

#pragma GCC optimize(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           \
    "-fdelete-null-pointer-checks,inline-functions-called-once,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-falign-functions,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2", \
    3, 2)
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#define debug(a) std::cerr << #a << "=" << a << "\n"
#define debug2(a, b) \
  std::cerr << #a << "=" << a << " " << #b << "=" << b << "\n"
#define debug3(a, b, c)                                                    \
  std::cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" \
            << c << "\n"
#define debug4(a, b, c, d)                                                 \
  std::cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" \
            << c << " " << #d << "=" << d << "\n"
// #define int long long
using namespace std;
int n, m;
struct p {
  int v, w;
  bool operator<(const p& t) const {
    if (v < t.v)
      return true;
    else
      return w < t.w;
  }
};
void solve() {
  cin >> n;
  vector<p> a(n);
  for (auto& [x, y] : a) {
    cin >> x >> y;
  }
  sort(begin(a), end(a));
  int l = 0, r = 1e9;
  auto check = [&](int x) -> bool {
    vector<int> A;
    vector<int> B;
    for (int i = 0; i < n; i++) {
      if (a[i].v < x) {
        A.push_back(a[i].w);
      } else {
        B.push_back(a[i].w + a[i].v - x);
      }
    }
    int t1 = A.size();
    int t2 = B.size();
    sort(begin(A), end(A));
    sort(begin(B), end(B));
    if (t2 < t1)
      return false;
    else {
      int i = 0, j = 0;
      while (i < t1 and j < t2) {
        if (A[i] <= B[j])
          i++, j++;
        else
          j++;
      }
      if (i == t1)
        return true;
      else
        return false;
    }
  };
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << ans << "\n";
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), std::cout.tie(0);
  cout << std::fixed << std::setprecision(15);
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  int __;
  cin >> __;
  while (__--) solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

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
Runtime Error

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:


result: