QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614158 | #8831. Chemistry Class | Heshu | RE | 0ms | 0kb | C++14 | 1.1kb | 2024-10-05 15:44:51 | 2024-10-05 15:44:57 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
const ll N=1145140,M=1919810,inf=1e18+5;
ll T,n,nm,a[N],w[N];
ll A,B,m;
bool vis[N];
ll st[N];
ll l[N],r[N];
void del(ll x){
l[r[x]]=l[x];
r[l[x]]=r[x];
}
void solve(){
cin>>m;
for(int i=1;i<=nm;++i) a[i]=w[i];
for(int i=1;i<=m;++i){
ll x,v;
cin>>x>>v,a[x]=v;
}
for(int i=1;i<=nm;++i) w[i]=a[i],vis[i]=0,l[i]=i-1,r[i]=i+1;
sort(a+1,a+nm+1);
cin>>A>>B;
ll maxn=-1;
for(int i=1;i<=nm;i+=2) maxn=max(maxn,a[i+1]-a[i]);
if(maxn>A){
cout<<"-1\n";
return;
}
ll nm=2*n,ans=0,fl=0; //是否有多的未匹配点
for(int i=1;i<=nm;++i){
if(vis[i]) continue;
if(abs(a[r[i]]-a[i])<=B){
if(fl&&abs(a[r[r[i]]]-a[l[i]])>A){
fl^=1;
continue;
}
vis[i]=vis[r[i]]=1;
del(i),del(r[i]);
++ans;
}
else fl^=1;
}
cout<<ans<<'\n';
}
int main(){
//freopen("dove.in","r",stdin);
//freopen("dove.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>T>>n; nm=2*n;
for(int i=1;i<=2*n;++i) cin>>w[i];
while(T--) solve();
return 0;
}/*
1 5
1 4 5 7 8 9 11 15 17 20
0
8 2*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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