QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275237#6525. New Housesucup-team1321#WA 82ms3688kbC++232.1kb2023-12-04 15:26:052023-12-04 15:26:05

Judging History

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

  • [2023-12-04 15:26:05]
  • 评测
  • 测评结果:WA
  • 用时:82ms
  • 内存:3688kb
  • [2023-12-04 15:26:05]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (auto i = 0; i < a; i++)
#define rep2(i, a) for (auto i = 0; i < a; i++)
#define rep3(i, a, b) for (auto i = a; i < b; i++)
#define rep4(i, a, b, c) for (auto i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

void solve() {
  int n, m;
  cin >> n >> m;
  vc<pii> a(n);
  rep(i, n) cin >> a[i].first >> a[i].second;
  ll res = 0;
  if (2 * n - 1 <= m) {
    ll ans = 0;
    rep(i, n) ans += a[i].second;
    cmax(res, ans);
  }
  int t = 0;
  if (m == n) {
    t = 0;
  } else if (m == n + 1) {
    t = 1;
  } else if (m == n + 2) {
    t = 2;
  } else {
    t = (m - n + 1) / 2;
  }
  cmin(t, n - 1);
  ll ans = 0;
  rep(i, n) ans += a[i].first;
  cmax(res, ans);
  sort(all(a),
       [&](auto x, auto y) { return x.second - x.first > y.second - y.first; });
  int rem = n;
  int i = 0;
  while (t--) {
    if (a[i].second > a[i].first) {
      ans += a[i].second - a[i].first;
      rem -= 1;
    }
    i++;
    if (rem >= 2) {
      cmax(res, ans);
    } else {
      break;
    }
  }
  cout << res << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  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: 0ms
memory: 3688kb

input:

3
4 5
1 100
100 1
100 1
100 1
2 2
1 10
1 10
2 3
100 50
1 1000

output:

400
2
1050

result:

ok 3 number(s): "400 2 1050"

Test #2:

score: -100
Wrong Answer
time: 82ms
memory: 3688kb

input:

100000
6 11
191141536 365120521
799679686 648574232
102602909 467685128
405440859 796808887
384858152 191995380
433392826 195648471
5 13
831367906 510447872
795639287 575551283
811207605 176441088
240156289 946977042
133416463 721098873
5 5
806744021 699586200
630510306 637827160
49223781 641709297
...

output:

3247545200
4106290713
2653993029
5122532137
5570513606
2031887824
2044500908
1857678917
6815058419
2237593918
6646615756
5393412666
3690874076
5497726904
5513905900
5367943915
4705403467
2411992217
3430587752
4875673031
3921151709
1445672728
2692878616
3833748807
2716183054
974485573
6464787173
8839...

result:

wrong answer 12th numbers differ - expected: '5638337819', found: '5393412666'