QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#543304 | #8831. Chemistry Class | ucup-team1069# | WA | 7ms | 5196kb | C++23 | 1.0kb | 2024-09-01 15:47:40 | 2024-09-01 15:47:41 |
Judging History
answer
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#ifndef LOCAL
#define cerr if(false)cerr
#endif
using namespace std;
using ll = long long;
const int N = 1e6 + 123;
void debug(vector<int>&a, string end="\n") {
for (int x : a) {
cerr << x << " ";
}
cerr << end;
}
int n, A, B, a[N];
int dist(int i, int j) {
return abs(a[i] - a[j]);
}
void solve() {
cin >> n >> A >> B;
for (int i = 0 ; i < 2 * n ; ++ i) {
cin >> a[i];
}
sort(a, a + 2 * n);
for (int i = 1 ; i < 2 * n ; i += 2) {
if (a[i] - a[i - 1] > A) {
cout << -1;
return;
}
}
int k = -1;
int ans = 0;
for (int i = 0 ; i < n * 2 ; ++ i) {
if (dist(i, i + 1) <= B && (k == -1 || (i + 2 < n * 2 && dist(k, i + 2) <= A))) {
ans++;
i++;
continue;
}
if (k == -1) {
k = i;
} else {
k = -1;
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 7ms
memory: 5196kb
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...
output:
199996
result:
wrong answer 1st numbers differ - expected: '0', found: '199996'