QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275136 | #6525. New Houses | ucup-team1321# | WA | 83ms | 3960kb | C++23 | 1.9kb | 2023-12-04 14:00:33 | 2023-12-04 14:00:34 |
Judging History
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;
if (n == 1) {
cout << a[0].second << "\n";
return;
}
int t = (m - n + 1) / 2;
ll res = 0;
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;
rep(i, t) {
if (a[i].second >= a[i].first) {
ans += a[i].second - a[i].first;
rem -= 1;
if (rem == 1) {
ans += a.back().second - a.back().first;
}
cmax(res, ans);
}
}
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: 3692kb
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: 83ms
memory: 3960kb
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 2016546481 2044500908 1857678917 6815058419 2237593918 6646615756 5393412666 3532921538 5497726904 5513905900 5367943915 4705403467 2411992217 3430587752 4875673031 3921151709 1445672728 2692878616 3833748807 2716183054 974485573 6464787173 8839...
result:
wrong answer 6th numbers differ - expected: '2031887824', found: '2016546481'