QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762913 | #8831. Chemistry Class | chatoyane | WA | 74ms | 25192kb | C++20 | 1.5kb | 2024-11-19 17:15:12 | 2024-11-19 17:15:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define endl '\n'
using db = double;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
void solve()
{
LL n, A, B;
cin >> n >> A >> B;
// cerr << "A = " << A << " B = " << B << endl;
vector<LL> a(n * 2);
for (int i = 0; i < n * 2; ++i)
cin >> a[i];
sort(a.begin(), a.end());
multiset<LL> ms(a.begin(), a.end());
int ok = 1, ans = 0;
for (int i = 0; i < n; ++i)
{
auto it = ms.begin();
LL x = *it;
// cerr << "x + A = " << x + A << endl;
// cerr << "x + B = " << x + B << endl;
auto itA = prev(ms.upper_bound(x + A));
auto itB = prev(ms.upper_bound(x + B));
if (itB != it)
{
ans++;
// cerr << *it << " " << *itB << endl;
ms.erase(it);
ms.erase(itB);
}
else if (itA != it)
{
// cerr << *it << " " << *itA << endl;
ms.erase(it);
ms.erase(itA);
}
else
{
ok = 0;
break;
}
}
if (ok)
cout << ans << endl;
else
cout << -1 << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
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: 3796kb
input:
4 1 2 1 42 69 2 3 1 1 2 3 4 2 5 1 6 1 3 4 5 19 1 1 7 8 9 10 11 12 13 14 20
output:
-1 2 1 4
result:
ok 4 number(s): "-1 2 1 4"
Test #2:
score: -100
Wrong Answer
time: 74ms
memory: 25192kb
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...
output:
-1
result:
wrong answer 1st numbers differ - expected: '0', found: '-1'