QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708183 | #8831. Chemistry Class | ucup-team134# | RE | 1ms | 5844kb | C++14 | 1.5kb | 2024-11-03 20:06:58 | 2024-11-03 20:06:59 |
Judging History
answer
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=3e5+10;
ll A,B,a[maxn],dp[maxn],inf=1e18;
int fdl[maxn],n;
int main(){
///freopen("test.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--){
scanf("%d %lld %lld",&n,&A,&B);
n=2*n;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
sort(a+1,a+n+1);
dp[1]=-inf;
fdl[1]=1;
int lp=1;
for(int i=2;i<=n;i++){
while(a[i]-a[lp]>A)lp++;
fdl[i]=i;
if(a[i]-a[i-1]<=B){
fdl[i]=i-2;
fdl[i]=min(fdl[i],fdl[i-2]);
}
int pom=max(fdl[i-1],lp);
if((i-pom)%2==0)pom++;
dp[i]=-inf;
dp[i]=max(dp[pom-1]+(i-pom)/2,dp[i]);
if(a[i]-a[i-1]<=B)dp[i]=max(dp[i],dp[i-2]+1);
}
if(dp[n]<0)printf("-1\n");
else printf("%lld\n",dp[n]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5844kb
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...