QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658748 | #8831. Chemistry Class | ucup-team3661# | RE | 0ms | 3568kb | C++20 | 1.3kb | 2024-10-19 17:31:41 | 2024-10-19 17:31:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1e9+10;
ll A,B;
int solve(vector<ll>C){
int N=C.size()/2;
vector<int>right(2*N);
int l=0,r=0;
while(r<2*N){
while(r<2*N-1&&C[r+1]-C[r]<=B)r++;
for(int i=l;i<=r;i++)right[i]=r;
l=r+1;
r=l;
}
int ret=0;
int pos=0;
while(pos<=2*N-2){
assert(pos%2==0);
if(C[pos+1]-C[pos]<=B){
ret++;
pos+=2;
continue;
}
int nxt_pos=-1;
int r=pos+1;
while(C[r]-C[pos]<=A && r<2*N){
assert(r%2==1);
int sz=(right[r]-r+1);
nxt_pos=r;
if(sz%2==0){
r=right[r]+1;
}
else{
break;
}
}
assert(nxt_pos%2==1);
ret+=(nxt_pos-pos-1)/2;
pos=nxt_pos;
}
return ret;
}
int main(){
int T;cin>>T;
while(T--){
int N;cin>>N>>A>>B;
vector<ll>D(2*N);
for(int i=0;i<2*N;i++)cin>>D[i];
sort(D.begin(),D.end());
vector<ll>C;
int ans=0;
bool ok=true;
for(int i=0;i<2*N;i++){
ll c=D[i];
if(C.empty()||c-C.back()<=A){
C.push_back(c);
}
else if(C.size()%2==1){
ok=false;
}
else{
ans+=solve(C);
C.clear();
C.push_back(c);
}
}
if(C.size()%2==0){
ans+=solve(C);
}else{
ok=false;
}
if(!ok)ans=-1;
cout<<ans<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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
Runtime Error
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...