QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629867 | #8831. Chemistry Class | ucup-team4352# | RE | 0ms | 3580kb | C++23 | 1.4kb | 2024-10-11 15:15:36 | 2024-10-11 15:15:37 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
ll t[200005];
void solve(){
int n;
ll a,b;
cin>>n>>a>>b;
n<<=1;
for(int i=1;i<=n;i++) cin>>t[i];
sort(t+1,t+n+1);
for(int i=1;i<=n;i+=2){
if(t[i]+a<t[i+1]){
cout<<"-1\n";
return;
}
}
int ans=t[2]-t[1]<=b,lastL=1;
int lastans=ans;
for(int i=3;i<=n;i+=2){
// cout<<i<<" "<<lastL<<" "<<ans<<"\n";
if(t[i+1]-t[lastL]>a||lastans){
lastL=i;
lastans=0;
if(t[i+1]-t[i]<=b){
ans++;
lastL=i;
lastans=1;
continue;
}
continue;
}
if(t[i]-t[i-1]<=b){
ans++;
lastans=0;
continue;
}
if(t[i+1]-t[i]<=b){
ans++;
lastans=1;
lastL=i;
continue;
}
lastans=0;
lastL=i;
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t=1;
cin>>t;
while(t--)solve();
return 0;
}
/*
4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
1
5 19 1
1 7 8 9 10 11 12 13 14 20
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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...